Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / Interesting Trick to Calculate Number of Objects in a Pyramid of n-Layers

Author
Message
Jeff032
17
Years of Service
User Offline
Joined: 13th Aug 2007
Location:
Posted: 18th Sep 2007 18:08
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
Chris K
21
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 18th Sep 2007 19:30
What would a 5 dimensional pyramid be? Where every layer is a pentagon? Because I don't think you can make that.

-= Out here in the fields, I fight for my meals =-
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 18th Sep 2007 21:38 Edited at: 18th Sep 2007 21:41
For the 3D one it's


For 4D


These seem completely random but they work
Hmmm... I've noticed that the 3D one is simply accumulating n each turn


I think 5D doesn't work

In programming, nothing exists
Jeff032
17
Years of Service
User Offline
Joined: 13th Aug 2007
Location:
Posted: 18th Sep 2007 22:18
I guess I didn't look at it enough. Starting at 4 "dimensions", the formula seems to go away that I don't understand yet; at 5 "dimensions" I suppose it would be completely theoretical.

I'll post it later and maybe someone could figure out how 4+ would work.

@OBese87
It seems that you found formulas that will calculate the number in the given row, but not the total number in a stack with the given number of rows. But maybe I just misunderstood.

Space Game WIP
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 18th Sep 2007 22:22
Nope you understood me, I just didn't understand you

In programming, nothing exists

Login to post a reply

Server time is: 2024-11-19 07:36:27
Your offset time is: 2024-11-19 07:36:27