Guest User

Untitled

a guest
Jun 20th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. typedef struct {
  4. int bottle;
  5. int cap;
  6. } trace;
  7.  
  8. int bonus24(int beer, int cap_bonus, int bottle_bonus,trace* t)
  9. {
  10. // minus bottle & cap changed to bonus
  11. t->bottle -= bottle_bonus * 4;
  12. t->cap -= cap_bonus * 2;
  13.  
  14. // every steps increasesd beer
  15. printf("b: %d; c: %d; b: %d\n", beer, cap_bonus, bottle_bonus);
  16.  
  17. int bonus = cap_bonus + bottle_bonus;
  18.  
  19. // add bottle & cap by bonus
  20. t->bottle += bonus;
  21. t->cap += bonus;
  22.  
  23. printf("left bottle: %d, left cap: %d\n", t->bottle, t->cap);
  24.  
  25. if (bonus == 0)
  26. {
  27. return beer;
  28. }
  29. return beer + bonus24(bonus, bonus / 2, (bonus+bonus/2) / 4, t);
  30. }
  31.  
  32. int main(int argc, char *argv[])
  33. {
  34. int i;
  35.  
  36.  
  37. for (i = 1; i < 25; i++)
  38. {
  39. int beer = i / 2;
  40. trace t = { .bottle = beer, .cap = beer };
  41. printf ("%d: beer: %d\n", i, bonus24(beer, beer / 2, (beer+beer/2) / 4, &t));
  42. }
  43. return 0;
  44. }
Add Comment
Please, Sign In to add comment