Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- typedef struct {
- int bottle;
- int cap;
- } trace;
- int bonus24(int beer, int cap_bonus, int bottle_bonus,trace* t)
- {
- // minus bottle & cap changed to bonus
- t->bottle -= bottle_bonus * 4;
- t->cap -= cap_bonus * 2;
- // every steps increasesd beer
- printf("b: %d; c: %d; b: %d\n", beer, cap_bonus, bottle_bonus);
- int bonus = cap_bonus + bottle_bonus;
- // add bottle & cap by bonus
- t->bottle += bonus;
- t->cap += bonus;
- printf("left bottle: %d, left cap: %d\n", t->bottle, t->cap);
- if (bonus == 0)
- {
- return beer;
- }
- return beer + bonus24(bonus, bonus / 2, (bonus+bonus/2) / 4, t);
- }
- int main(int argc, char *argv[])
- {
- int i;
- for (i = 1; i < 25; i++)
- {
- int beer = i / 2;
- trace t = { .bottle = beer, .cap = beer };
- printf ("%d: beer: %d\n", i, bonus24(beer, beer / 2, (beer+beer/2) / 4, &t));
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment