Pyramid scheme formula in PHP?

I am working on a referral system - the formula is exactly like the pyramid / ponzi scheme.

The system works as follows:

The initial user subscribes (level 1) The
initial user refers to 3 friends (level 2)
Each of these three friends refers to another 3, (tier3)
, etc.

What will be the mathematical formula for this?
How could I code something in PHP, where I could enter a number, and then it would give me the number of levels that it fell, and semi-visual.

i.e.: I enter 13 - displays the text "3 tiers"and then displays

     o
     |
    ooo
   / | \
 ooooooooo
+3
source share

All Articles