Thread: How would I do this using recursion?

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    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)

  2. #2
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    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/

  3. #3
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511

    Talking

    Sounds like a combinatorics problem- lots of recursive sol's!!!
    Mr. C: Author and Instructor

  4. #4
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    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?
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  5. #5
    Registered User
    Join Date
    Oct 2002
    Posts
    155
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Template Recursion Pickle
    By SevenThunders in forum C++ Programming
    Replies: 20
    Last Post: 02-05-2009, 09:45 PM
  2. Recursion... why?
    By swgh in forum C++ Programming
    Replies: 4
    Last Post: 06-09-2008, 09:37 AM
  3. a simple recursion question
    By tetra in forum C++ Programming
    Replies: 6
    Last Post: 10-27-2002, 10:56 AM
  4. To Recur(sion) or to Iterate?That is the question
    By jasrajva in forum C Programming
    Replies: 4
    Last Post: 11-07-2001, 09:24 AM
  5. selection sorting using going-down and going-up recursion
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-02-2001, 02:29 PM