Jump to content

Geometric progression?


iCeR

Recommended Posts

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

Link to comment
Share on other sites

<?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";
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.