eniallator

Bitonic Checker | Python

Nov 15th, 2018
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. def check_bitonic(in_list):
  2.     if len(in_list) < 3 or in_list[0] >= in_list[1]:
  3.         return False
  4.  
  5.     decreasing = False
  6.  
  7.     for i, val in enumerate(in_list[1:-1]):
  8.         next_val = in_list[i + 2]
  9.         if val == next_val or decreasing and val < next_val:
  10.             return False
  11.         elif not decreasing:
  12.             decreasing = val > next_val
  13.     return decreasing
  14.  
  15. print('Should be true: ' + str(check_bitonic([1, 2, 1])))
  16. print('Should be true: ' + str(check_bitonic([1, 5, 7, 9, 8, 2])))
  17. print('Should be true: ' + str(check_bitonic([3, 4, 5, 1])))
  18.  
  19. print('Should be false: ' + str(check_bitonic([])))
  20. print('Should be false: ' + str(check_bitonic([1, 2])))
  21. print('Should be false: ' + str(check_bitonic([2, 1])))
  22. print('Should be false: ' + str(check_bitonic([1, 3, 5, 7])))
  23. print('Should be false: ' + str(check_bitonic([7, 5, 3, 1])))
  24. print('Should be false: ' + str(check_bitonic([1, 5, 5, 2])))
  25. print('Should be false: ' + str(check_bitonic([5, 2, 1, 3])))
Advertisement
Add Comment
Please, Sign In to add comment