Skip to content

Instantly share code, notes, and snippets.

@lastday154
Created December 2, 2017 12:19
Show Gist options
  • Select an option

  • Save lastday154/08e6005028d1a59d270111bdc8e476c0 to your computer and use it in GitHub Desktop.

Select an option

Save lastday154/08e6005028d1a59d270111bdc8e476c0 to your computer and use it in GitHub Desktop.
Referrer Grab
john = Passenger.create(name: "John")
jim = Passenger.create(name: "Jim", referrer: john)
bob = Passenger.create(name: "Bob", referrer: john)
$5 $3 $1
john -> jim -> alex -> Jane
-> bob -> sally
-> kim
cal_bonus(john) = $19
cal_bonus(jim) = $5
cal_bonus(bob) = $10
get_reffered(john) => [jim, bob];
int bonus_payouts[] = {5, 3, 1}
int level = sizeof(bonus_payouts)/sizeof(bonus_payouts[0]); -> 3
// cal_bonus(john, 2, 0);
int bonusIndex = 0;
int cal_bonus(id, height, bonusIndex) {
int bonus = 0;
//int bonusIndex = level - height - 1;
int referrers[] = get_reffered(id);
int n = sizeof(referrers)/sizeof(int);
if (height == 0) {
return bonus_payout[level-1];
}
for(int i=0; i< n; i++) {
bonus = bonus + bonus_payouts[bonusIndex] + cal_bonus(referrers[i], height-1, bonusIndex+1); // cal_bonus(bob, 1)
}
return bonus;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment