fork download
  1. def wall(height, width):
  2. count = 0
  3. x, y, angle = 1, 1, True
  4. map = {i: [None for _ in range(width + 2)] for i in range(height + 2)}
  5. while count < height * width:
  6. if 0 < x <= height and 0 < y <= width:
  7. count = count + 1
  8. map[x][y] = count
  9. else:
  10. if angle:
  11. try:
  12. map[x][y + 1]
  13. y = y + 1
  14. except:
  15. x = x + 1
  16. else:
  17. try:
  18. map[x + 1][y]
  19. x = x + 1
  20. except:
  21. y = y + 1
  22. angle = not angle
  23. if angle:
  24. x, y = x - 1, y + 1
  25. else:
  26. x, y = x + 1, y - 1
  27.  
  28. for v in map.values():
  29. l = ["%0{}d".format(len(str(count))) % i for i in v if i]
  30. if len(l):
  31. print(" ".join(l))
  32.  
  33. print()
  34.  
  35.  
  36. for x in [(3,3),(4,2),(3,5),(1,8)]:
  37. wall(*x)
Success #stdin #stdout 0.02s 27712KB
stdin
Standard input is empty
stdout
1 2 6
3 5 7
4 8 9

1 2
3 5
4 6
7 8

01 02 06 07 12
03 05 08 11 13
04 09 10 14 15

1 2 3 4 5 6 7 8