I'm working on a referral system - the formula is exactly like the pyramid/ponzi scheme.
The system works like this:
The initial user signs up (tier 1)
The initial user refers 3 friends (tier 2)
Each of those 3 friends refer another 3, (tier3)
What would be the mathematical formula for that? (I think it's called geometric progression)
How could I code up something in PHP where I could enter a number and it will then give me the number of tiers it has gone down and a semi-visual.
ie: I enter 13 - it displays the text "3 tiers" and then displays
/ | \\
Mathematically, each level goes in powers of 3. The first line is 3^0, second = 3^1, third = 3^2 etc.
The sum of these is 3^0 + 3^1 + 3^2 + ... 3^n. The general formula for the sum of n tiers is given as something like:
s = (1 - 3^n)(1 - 3)
= (3^n - 1)/2
=> 2s = 3^n - 1
=> 2s + 1 = 3^n
=> n = log(2s + 1) / log(3)
= log(2s + 1, 3) //php notation
If the number isn't the exact total, it will return a number lower than the row they're on but greater than the row above, so ceil() it:
return ceil(log(2s + 1, 3));
As for the diagram bit, I'll leave that to you. It depends on how you want it displayed; with ascii or with graphics and the diagram itself would be a fair amount of code to be giving away for free.
Perfect! Thanks Jake Arkinstall
Did the visual with ease after that..