Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def minimum_bribes(queue: list):
- #assuming starting with 1
- # check if its minimum
- # eval movimiento negativo
- length = len(queue)
- bribes = 0
- enum_list = list(enumerate(queue))
- for tuple_number in enum_list:
- position = tuple_number[0] + 1
- # if current number is higher than next number I must evaluate the difference because it bribed
- second_cond = True if position == length else (tuple_number[1] < enum_list[tuple_number[0] + 1][1])
- if position > tuple_number[1] and second_cond:
- continue
- dif = abs(position - tuple_number[1])
- if dif > 2:
- return 'Too chaotic'
- bribes += dif
- return bribes
- def main():
- assert (minimum_bribes([2, 1, 5, 3, 4]) == 3)
- assert (minimum_bribes([2,3,4,5,6,7,1]) == 6)
- assert (minimum_bribes([2, 5, 1, 3, 4]) == 'Too chaotic')
- assert (minimum_bribes([5, 1, 2, 3, 7, 8, 6, 4]) == 'Too chaotic')
- assert (minimum_bribes([1, 2, 5, 3, 7, 8, 6, 4]) == 7)
- assert (minimum_bribes([1, 2, 5, 3, 4, 7, 8, 6]) == 4)
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement