Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for The Fastest Horse by wo.tomasz
def strtime2sec(strtime: str) -> int:
[m,s] = strtime.split(':')
return 60*int(m) +int(s)
def fastest_horse(horses: list) -> int:
racing = [list(enumerate([strtime2sec(horse_time) for horse_time in race])) for race in horses] #convert results on second and enumerate
winners = [sorted(race, key=lambda horse_time: horse_time[1])[0][0] for race in racing] #sort by time and get winners
return max(set(winners), key=winners.count)+1 #find the most frequent winner
if __name__ == '__main__':
print("Example:")
print(fastest_horse([['1:13', '1:26', '1:11']]))
#These "asserts" using only for self-checking and not necessary for auto-testing
assert fastest_horse([['1:13', '1:26', '1:11'], ['1:10', '1:18', '1:14'], ['1:20', '1:23', '1:15']]) == 3
print("Coding complete? Click 'Check' to earn cool rewards!")
April 10, 2021
Comments: