fork download
  1. #!/usr/bin/env python3
  2. '''
  3. 1,1, 4,5
  4. 3,2, 5,6
  5. 5,4, 7,8
  6. 7,5, 8,9
  7.  
  8. 2,1, 2,5
  9. 4,2, 3,6
  10. 6,4, 5,8
  11. 8,5, 6,9
  12.  
  13. i, roundUp(i/2) +isGreaterThanMiddle, adding_3or1, adding4
  14. '''
  15.  
  16. import math
  17. def round_up_half(i):
  18. ''' 1,2,3,4,5,6,7,8 => 1,1,2,2,3,3,4,4 '''
  19. return math.ceil(i/2)
  20.  
  21. def is_greater_than_middle(i):
  22. ''' 1,2,3,4,5,6,7,8 => 0,0,0,0,1,1,1,1 '''
  23. if i <= 4:
  24. return 0
  25. else:
  26. return 1
  27.  
  28. def first_pos(i):
  29. ''' 1,2,3,4,5,6,7,8 => 1,1,2,2,4,4,5,5 '''
  30. return round_up_half(i) + is_greater_than_middle(i)
  31.  
  32. def adding_3or1(i):
  33. if i % 2 == 0:
  34. return 1
  35. else:
  36. return 3
  37.  
  38. def second_pos(i):
  39. return first_pos(i) + adding_3or1(i)
  40.  
  41. def third_pos(i):
  42. return first_pos(i) + 4
  43.  
  44. def region_and_pos(i):
  45. return [i, first_pos(i), second_pos(i), third_pos(i)]
  46.  
  47. def describe_all():
  48. for i in range(1,9):
  49. print(region_and_pos(i))
  50.  
  51. describe_all()
Success #stdin #stdout 0.02s 9108KB
stdin
Standard input is empty
stdout
[1, 1, 4, 5]
[2, 1, 2, 5]
[3, 2, 5, 6]
[4, 2, 3, 6]
[5, 4, 7, 8]
[6, 4, 5, 8]
[7, 5, 8, 9]
[8, 5, 6, 9]