I was reading through a book yesterday, and I came across said trick, and I wondered how many people actually knew it, and then I wondered how many people actually needed to know it (and decided the answer was 0
), but it was kind of cool anyway, so
Come up with the fastest code you can that will calculate the number of objects in a pyramid of x-dimensions where x >= 1 and with y-layers where y >= 1
Just to clarify:
One dimesion would look like
*
*
*
*
1 Layer = 1 Object
2 Layers = 2 Objects, etc
Two dimensions:
___*
__*_*
_*_*_*
*_*_*_*
1 Layer = 1 Object
1 Layers = 3 Objects, etc
Three dimensions would be a triangular pyramid, the top object would be supported by 3 underneath, each of which were supported by 3 more
Four dimensions would be a square pyramid, etc.
So a few people please give it a shot, and then I'll post my function.
Space Game WIP