def clean_input_file(file_name): inp = open(file_name) inp = inp.read() inp = inp.split('\n') cases = int(inp[0]) inp.pop(0) inp.pop() return inp, cases def cruise_control(distance, horse): return float(distance - horse[0]) / horse[1] def get_speeds(distance, horses): speeds = [] for horse in horses: speeds.append(cruise_control(distance, horse)) return distance / max(speeds) input_file, cases = clean_input_file('test.in') write_file = open('solution.txt', 'w+') row = 0 for case in range(cases): case_info = input_file[row].split(' ') speed = int(case_info[0]) n_horses = int(case_info[1]) horses = [] for _ in range(n_horses): row += 1 horse = input_file[row].split(' ') horses.append((int(horse[0]), int(horse[1]))) write_file.write("Case #{}: {}\n".format(case + 1, "{0:.2f}".format(get_speeds(speed, horses)))) row += 1
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Discussion on: Daily Coding Puzzles - Nov 11th - Nov 16th
Replies for: Friday - Cruise Control (Code Jam): Annie is a bus driver with a high-stress job. She tried to unwind by going on a Caribbean cruise, but that al...
For further actions, you may consider blocking this person and/or reporting abuse