fork download
  1. w = 17
  2. h = 11
  3. tab = [[0 for i in range(w)] for j in range(h)]
  4.  
  5. def p(t):
  6. for item in t:
  7. print item
  8.  
  9. # w ktora strone lecimy: up=>po ukosie w gorne prawo; down=>po ukosie w dolne lewo
  10. direction = "up"
  11. # liczba do wpisania
  12. i = 1
  13. # miejsce do wpisania
  14. x = 0
  15. y = 0
  16.  
  17. while i<=w*h:
  18. # print i, x, y, direction
  19. # p(tab)
  20. tab[y][x] = i
  21.  
  22. # walkaround dla przypadkow gdy po zrobieniu kroku okazuje sie ze x<0 i y>h albo x>w i y<0 (rogi planszy)
  23. mod_x = False
  24. mod_y = False
  25.  
  26. if direction == "up":
  27. x += 1
  28. y -= 1
  29.  
  30. else:
  31. x -= 1
  32. y += 1
  33.  
  34. if x < 0: # wylezlismy z lewej
  35. direction = "up"
  36. x = 0
  37. mod_x = True
  38.  
  39. if y < 0: # z gory
  40. direction = "down"
  41. y = 0
  42. mod_y = True
  43.  
  44. if x >= w: # z prawej
  45. direction = "down"
  46. if not mod_y:
  47. y += 2
  48. else:
  49. y += 1
  50. x -= 1
  51.  
  52. if y >= h: # z dolu
  53. direction = "up"
  54. if not mod_x:
  55. x += 2
  56. else:
  57. x += 1
  58. y -= 1
  59. i += 1
  60.  
  61. p(tab)
Success #stdin #stdout 0.09s 8912KB
stdin
Standard input is empty
stdout
[1, 2, 6, 7, 15, 16, 28, 29, 45, 46, 66, 67, 88, 89, 110, 111, 132]
[3, 5, 8, 14, 17, 27, 30, 44, 47, 65, 68, 87, 90, 109, 112, 131, 133]
[4, 9, 13, 18, 26, 31, 43, 48, 64, 69, 86, 91, 108, 113, 130, 134, 151]
[10, 12, 19, 25, 32, 42, 49, 63, 70, 85, 92, 107, 114, 129, 135, 150, 152]
[11, 20, 24, 33, 41, 50, 62, 71, 84, 93, 106, 115, 128, 136, 149, 153, 166]
[21, 23, 34, 40, 51, 61, 72, 83, 94, 105, 116, 127, 137, 148, 154, 165, 167]
[22, 35, 39, 52, 60, 73, 82, 95, 104, 117, 126, 138, 147, 155, 164, 168, 177]
[36, 38, 53, 59, 74, 81, 96, 103, 118, 125, 139, 146, 156, 163, 169, 176, 178]
[37, 54, 58, 75, 80, 97, 102, 119, 124, 140, 145, 157, 162, 170, 175, 179, 184]
[55, 57, 76, 79, 98, 101, 120, 123, 141, 144, 158, 161, 171, 174, 180, 183, 185]
[56, 77, 78, 99, 100, 121, 122, 142, 143, 159, 160, 172, 173, 181, 182, 186, 187]