Advertisement
VikkaLorel

regularHexagone

May 29th, 2018
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. import time
  2.  
  3. def nextLevelRec(shape, step):
  4.     shape.append(shape[-1] + 12)
  5.     return(nextLevelRec(shape, step - 1) if step > 0 else shape)
  6.  
  7. def nextLevelIter(shape, step):
  8.     x = 6;
  9.     while (step > 0):
  10.         shape = shape + x + 12
  11.         x += 12
  12.         step -= 1
  13.     return(shape)
  14.  
  15. shape = 6
  16. step = int(input("Max step to go ? ")) - 1
  17. if step > 0:
  18.     shape = nextLevelIter(shape, step)
  19. print("Number of tiles (iterative) : ", shape)
  20.  
  21. shape = [6]
  22. if step > 0:
  23.     shape = nextLevelRec(shape, step-1)
  24. print("Number of tiles (recursive) : ", sum(shape))
  25.  
  26. shapeCollection = list()
  27. step = int(input("Max step to go ?"))
  28. t = time.clock()
  29. for x in range(step):
  30.     shape = [6]
  31.     if (x > 0):
  32.         shape = nextLevelRec(shape, x-1)
  33.     shapeCollection.append(sum(shape))
  34. t1 = time.clock() - t
  35. print("Number of tiles for each shape : ", shapeCollection)
  36. shape = 6
  37. t = time.clock()
  38. for x in range(step):
  39.     if step > 0:
  40.         shape = nextLevelIter(shape, step)
  41. t2 = time.clock() - t
  42. print("Number of tiles for each shape : ", shapeCollection)
  43. print("benchmark", t1, t2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement