# How would I do this using recursion?

• 12-19-2002
Josephus_1
How would I do this using recursion?
Suppose I start with N jelly beans abd k friends. I divide the jelly beans evebly to all friends. I eat any leftovers rather thangiving my friends parts of a bean. One friend eats all his beans, and the others divide their beans the same way, but each has one less friend. (for instance, if I start with 50 beans and 4 friends, 3 of these friends will each divide 12 beans to three of their friends). The process ends when all the beans have been eaten or the person has no friends. Assume that all the people in this process are different. If I start out with 400 beans and 6 friends, how many different people will be lucky enough to eat more than one jelly bean when this process terminates?

(I can code it but I need to know what it's asking, precisely/psuedocode)
• 12-19-2002
RoD
i know nothing bout recursion, but i am in a "i gotta do something to be sane" mood so here are some links i got when looking up recursion. If i'm no help ignore me.

http://www.stickysauce.com/tutorials...s/lesson16.htm

http://www.cse.ucsc.edu/~ranger/cs1class/recurs.htm

http://www.recursionsw.com/
• 12-19-2002
Mister C
Sounds like a combinatorics problem- lots of recursive sol's!!!
• 12-19-2002
pianorain
I'm not sure if I understand the question. I think I'm confused about the process. Check me on this.[list=1][*]I have 400 jelly beans and 6 friends. I give each friend 66 jelly beans, leaving me with 4 jelly beans, which I eat.[*]One of the friends eats all of his beans.[*]The other five friends evenly distribute their 66 jelly beans to five of their friends. Each of these five have 1 jelly bean left. I assume they eat them, since I did.[/list=1]A question: On the third step, do the five friends distribute jelly beans to a different set of five friends, or do we keep the jelly beans within the original six friends?
• 12-19-2002
Nakeerb
Quote:

I'm not sure if I understand the question. I think I'm confused about the process. Check me on this.
I have 400 jelly beans and 6 friends. I give each friend 66 jelly beans, leaving me with 4 jelly beans, which I eat.

One of the friends eats all of his beans.

The other five friends evenly distribute their 66 jelly beans to five of their friends. Each of these five have 1 jelly bean left. I assume they eat them, since I did.
A question: On the third step, do the five friends distribute jelly beans to a different set of five friends, or do we keep the jelly beans within the original six friends?.
They go to new people. A "Guy" gives 6 people 66 beans, which one person eats, and the "Guy" eats 4 beans. The remaining 5 people give I think it was 13 beans to 5 new people each. They get to eat I think it was 1 jelly bean. (you only count the ones who eat 2 or more beans, here), etc. Every new "set" of friends, one person always leaves by eating all his beans. It resembles those brancing-tree diagrams when you draw it