iCeR Posted March 21, 2011 Share Posted March 21, 2011 Hi, 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) etc. 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 o | ooo / | \ ooooooooo Quote Link to comment https://forums.phpfreaks.com/topic/231290-geometric-progression/ Share on other sites More sharing options...
sasa Posted March 21, 2011 Share Posted March 21, 2011 <?php $number = 41; echo $d = ceil(log(2*$number)/log(3))," tiers<br />\n"; $x = 1; for($i = 1; $i<$d;$i++){ echo str_repeat('o', $x),"<br />\n"; $number -= $x; $x *= 3; } echo str_repeat('o', $number),"<br />\n"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/231290-geometric-progression/#findComment-1190519 Share on other sites More sharing options...
iCeR Posted March 22, 2011 Author Share Posted March 22, 2011 Perfect! Thanks Sasa Quote Link to comment https://forums.phpfreaks.com/topic/231290-geometric-progression/#findComment-1190731 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.