Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Speedcubing is the hobby involving solving a variety of twisty puzzles, the most famous being the 3x3x3 puzzle or Rubik's Cube, as quickly as possible.
- In the majority of Speedcubing competitions, a Cuber solves a scrambled cube 5 times, and their result is found by taking the average of the middle 3 solves (ie. the slowest and fastest times are disregarded, and an average is taken of the remaining times).
- In some competitions, the unlikely event of a tie situation is resolved by comparing Cuber's fastest times.
- Write a function cube_times(times) that, given an array of floats times returns an array / tuple with the Cuber's result (to 2 decimal places) AND their fastest solve.
- For example:
- cube_times([9.5, 7.6, 11.4, 10.5, 8.1]) = (9.37, 7.6)
- # Because (9.5 + 10.5 + 8.1) / 3 = 9.37 and 7.6 was the fastest solve.
- Note: times will always be a valid array of 5 positive floats (representing seconds)
- '''
- def cube_times(times):
- max = times[0]
- min = times[1]
- for i in range(1, len(times)):
- if times[i] > max:
- max = times[i]
- if times[i] < min:
- min = times[i]
- # I've found the min and max elements of the list
- mediumElements = []
- for i in range(0, len(times)):
- if times[i] != min and times[i] != max:
- mediumElements.append(times[i])
- # My list with medium elements is ready
- sum = 0
- for i in range(0, len(mediumElements)):
- sum += mediumElements[i]
- average = sum / 3
- # Rounding average in 2 digits
- average = round(100 * average) / 100
- # New list = returned list
- returnedList = []
- returnedList.append(average)
- returnedList.append(min)
- # Convert the list to a tuple
- returnedTuple = tuple(returnedList)
- return returnedTuple
- # MAIN FUNCTION
- print()
- print("cube_times([10.5, 9.2, 8.4, 11.3, 12.6]) = " + str(cube_times([10.5, 9.2, 8.4, 11.3, 12.6])))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement