- 1

Write algorithm to find sum of the temperature of two test tubes which will produce the maximum temperature when combined.

12th Jan 2022, 6:28 AM
Divya Chinnu
Divya Chinnu - avatar
2 Answers
0
And your try?
12th Jan 2022, 6:28 AM
NEZ
NEZ - avatar
0
# python3 from itertools import combinations tubes = [{"num": 0, "temperature": 10}, {"num": 2, "temperature": 50}, {"num": 3, "temperature": 40}] # print(list(combinations(tubes, 2))) # [({'num': 0, 'temperature': 10}, {'num': 2, 'temperature': 50}), ({'num': 0, 'temperature': 10}, {'num': 3, 'temperature': 40}), ({'num': 2, 'temperature': 50}, {'num': 3, 'temperature': 40})] # calc the sum of the temperature of each combination result = list(map(lambda x: (x, x[0]["temperature"] + x[1]["temperature"]), combinations(tubes, 2))) # sorted by sum of temperature desc result.sort(key=lambda x: x[1], reverse=True) print(result[0]) # (({'num': 2, 'temperature': 50}, {'num': 3, 'temperature': 40}), 90)
12th Jan 2022, 7:07 AM
FanYu
FanYu - avatar