Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- def nextLevelRec(shape, step):
- shape.append(shape[-1] + 12)
- return(nextLevelRec(shape, step - 1) if step > 0 else shape)
- def nextLevelIter(shape, step):
- x = 6;
- while (step > 0):
- shape = shape + x + 12
- x += 12
- step -= 1
- return(shape)
- shape = 6
- step = int(input("Max step to go ? ")) - 1
- if step > 0:
- shape = nextLevelIter(shape, step)
- print("Number of tiles (iterative) : ", shape)
- shape = [6]
- if step > 0:
- shape = nextLevelRec(shape, step-1)
- print("Number of tiles (recursive) : ", sum(shape))
- shapeCollection = list()
- step = int(input("Max step to go ?"))
- t = time.clock()
- for x in range(step):
- shape = [6]
- if (x > 0):
- shape = nextLevelRec(shape, x-1)
- shapeCollection.append(sum(shape))
- t1 = time.clock() - t
- print("Number of tiles for each shape : ", shapeCollection)
- shape = 6
- t = time.clock()
- for x in range(step):
- if step > 0:
- shape = nextLevelIter(shape, step)
- t2 = time.clock() - t
- print("Number of tiles for each shape : ", shapeCollection)
- print("benchmark", t1, t2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement