fork download
  1. class Area:
  2. def __init__(self,height,width):
  3. self.square = []
  4. for i in range(width):
  5. for l in range(height):
  6. ul = i * (height + 1) + l + 1
  7. self.square.append([ul,ul+height+1,ul+height+2,ul+1])
  8. self.length = len(self.square) * 2 + 1
  9.  
  10. def show_points(self,num):
  11. if 0 < num < self.length:
  12. p, q = (num - 1) // 2, num % 2
  13. if q:
  14. ans = self.square[p][:3]
  15. return ans
  16. else:
  17. ans = self.square[p]
  18. ans.pop(1)
  19. return sorted(ans)
  20.  
  21. def show_all(self):
  22. for i in range(1,self.length):
  23. print("#{}: {}".format(i,self.show_points(i)))
  24.  
  25. p = Area(2,2)
  26. p.show_all()
Success #stdin #stdout 0.02s 9172KB
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]