Crazy Problem

Posted:
in General Discussion edited January 2014
Ok, I'm going to start by saying that this is an assignment we had to do for computer sciences, I hand it in on thursday. I have a few Ideas of how to handle this but would like some input.

here goes:

A rich collector of gold coins has left a will giving instructions stating how his coins are going to be distributed to his family {5 children, 5 grandchildren and one butler}. his instructions are that, one coin is to be given to his to his butler, Then his eldest son is to get 1/5th of the remaining coins. Another coin is given to his Butler, then his second eldest child is given 1/5 of the remaining. This proceedure is repeated untill all the five children have their share. Finally, the reamaining coins are to be divided evenly among the five grandchildren. You are told that the collector had bettween 5 and 5000 coins. How many gold coins, exactly, did the collector have in his collection?



yeah its a tuff one.. I ahve five pages of calculations right now.. So how would you do it?

love

flick.

Comments

  • Reply 1 of 20
    ugh, this is one of those stupid combinatorics problems.



    Unless it's a demonic problem, there are more than 5 coins, because the Butler gets 5 coins. So 5 would be an acceptable answer if you round down the 1/5. if the divisions are supposed to be clean, then you have to separate, somehow, the quantities into integer quantities evenly divisible by 5.



    But there seems like a lot of criteria that is missing. I never took a discrete math class because I have little interest in combinatorics (I much prefer calculus based approaches). So I'm not really sure of the "Default" constraints here.



    Assuming the divisions need to be on clean integer boundaries, you need to find a number X0 where:



    (X0 - 1) % 5 = 0,

    X1 = (4(X0 - 1)/5) ,

    (X1 - 1) % 5 = 0,

    X2 = (4(X1 - 1)/5) ,

    (X2 - 1) % 5 = 0,

    X3 = (4(X2 - 1)/5) ,

    (X3 - 1) % 5 = 0,

    X4 = (4(X3 - 1)/5) ,

    (X4 - 1) % 5 = 0,

    X5 = (4(X0 - 1)/5) ,

    (X5) % 5 = 0;



    I'm assuming the Butler does not get a coin after the last child.



    Since you only have 4995 numbers to pick from, do a brute force algorithm to get the answer. It will take a really short amount of time to run on a modern computer (i.e. instant) and you should only need one simple C file (or whatever you're using) with a string of linked conditions in a for loop. That tests X0 from 5 to 5000.



    You can further narrow the loop by starting X0 at 6 and incrementing by 5 each time, since we set it up such that (X0 - 1) % 5 has to be 0.



    If you need to use a smarter approach to get credit, at least then you'll have the answer to check with. You could always solve for everything in terms of X5.
  • Reply 2 of 20
    mcqmcq Posts: 1,543member
    Splinemodel's brute-force approach is probably the first thing I'd try if I were given that problem, assuming every coin amount should be an integer number... only 4996 possibilities, so brute-force shouldn't be that difficult to implement (Splinemodel appears to have given the general algorithm already).
  • Reply 3 of 20
    I just got an email from my prof <I asked him for direction> I guess they didn't look this one over after they had writen it, and just today tried to work it out.. he said the right answer is 3000 < x < 3500,

    so that narrows it down..

    what I have is begin to look a lot like fire starter..

    I'm goign to hit this again.

    thanks for the suggestion!

    anymore?

    oh and the prof said they had come up with three diffrent ways to get this, one was really long, so I'm assuming my method was that one..



    Oh and at school they use a g++ complier.. where do I find this for my 12" PB? and or what does the mac use/have installed?

    flick.
  • Reply 4 of 20
    Unless I'm mistaken, g++ is integrated into gcc.



    But remember, I'm NOT a CS guy. I'm an EE, and for that matter I'm a signals guy, so I don't do a lot of compiling. . . I either script or assemble.



    I'm curious now. . . I might use the brute force method to find the answer. shouldn't take more than 40mins.
  • Reply 5 of 20
    I'm first year CS.

    I NEVER thought I'd be doing this stuff I actually think its fun!



    if your interested I could post another question we got, its more of a word problem.. but still a good mind job.

    let me know how your doing!

    i used the

    $ g++ sample.cpp

    it didn't know what I was talking about.. huh.

    flick.

    ::edit::: to eager to push send.. slow down and spell check!
  • Reply 6 of 20
    Code:


    [jnorair:~/Documents] jnorair% ./brutecoins

    Your number is 3121











    I won't publish the code until I know you've got the same answer.
  • Reply 7 of 20
    Quote:

    Originally posted by Flick Justice



    $ g++ sample.cpp





    I think you need to have the Developers' Tools installed. They are on the disks that came with your computer, but if you don't have those handy, you can download them from Apple.



    Also, (a dumb mistake from personal experience), don't use gcc (the C compiler) by mistake. (Yes, after just a couple of weeks between programming projects once, I forget the correct command.) The command you have is correct, except that if you don't have your home directory in your path (it isn't by default) then you might need "g++ ./sample".



    I was thinking about CS/EE, but lately I've been concentrating on EE and I forget things I don't use, so there's only a 50/50 chance of what I've written being correct.
  • Reply 8 of 20
    Quote:

    Originally posted by Splinemodel

    Code:


    [jnorair:~/Documents] jnorair% ./brutecoins

    Your number is 3121











    I won't publish the code until I know you've got the same answer.



    gulp.

    well I know my friend got that..

    I'll keep you posted on how i'm doing...

    flick.
  • Reply 9 of 20
    Did you get the answer? I think my program was less than 40 lines, (with plenty of spacing). If you don't have anything at this point, I suggest using the brute force method. If this is CS 1 for you, I don't expect that there are any expectations beyond this.
  • Reply 10 of 20
    Well I did get something.. I'll Try and write it here.. forgive the mess.

    c=(((((5g*[5/4])+1)[5/4]+1)[5/4]+1)[5/4]+1)[5/4]+1



    where c is the total gold coins and g is the number of coins inherited by each grandchild.



    or



    [(15625g+8404)/1024]=c





    I used the bash method.. and I came up with 3121.. which satifies the 3000 < x < 3500 window we were given.

    and also 5 < x < 5000 that was given with the problem.



    so can I see what you did now?

    flick.
  • Reply 11 of 20
    mcqmcq Posts: 1,543member
    PM me your source (so I see that you have a fully working solution ), and if I'm awake I'll PM you the version I have.
  • Reply 12 of 20
    Quote:

    Originally posted by MCQ

    PM me your source (so I see that you have a fully working solution ), and if I'm awake I'll PM you the version I have.



    If neither of you mind, could you post the code when you're done? I'm all curious now...
  • Reply 13 of 20
    yevgenyyevgeny Posts: 1,148member
    You can all call me a jerk, but posting one's homework on a forum for collective input into how to do it is probably not something that your teacher would approve of (I could be wrong). Generally, you need to figure out how to do these problems on your own. No, you won't get as good a grade, but you will learn how to do problem solving on your own and that is actually more useful in the real world than some grade.



    I like these problems as much as the next CS/Math guy, but it is somewhat inappropriate to query other people as to how to do your homework.
  • Reply 14 of 20
    Quote:

    Originally posted by Yevgeny

    You can all call me a jerk, but posting one's homework on a forum for collective input into how to do it is probably not something that your teacher would approve of (I could be wrong). Generally, you need to figure out how to do these problems on your own. No, you won't get as good a grade, but you will learn how to do problem solving on your own and that is actually more useful in the real world than some grade.



    I like these problems as much as the next CS/Math guy, but it is somewhat inappropriate to query other people as to how to do your homework.




    Im not calling you a jerk by any means, but I work as an AIX admin and I got buddies all over the country and we are always im'ing each other with questions and help. I don't really see how this is any different. My bosses call it "make it happen" and they love me for it!
  • Reply 15 of 20
    Quote:

    Originally posted by Yevgeny

    You can all call me a jerk, but posting one's homework on a forum for collective input into how to do it is probably not something that your teacher would approve of (I could be wrong). Generally, you need to figure out how to do these problems on your own. No, you won't get as good a grade, but you will learn how to do problem solving on your own and that is actually more useful in the real world than some grade.



    I like these problems as much as the next CS/Math guy, but it is somewhat inappropriate to query other people as to how to do your homework.




    Just looking for fresh Ideas, if you look at something for so long somtimes it becomes Impossible to see the solution, thanks to a few people here I've gotten back on track. AFTER today I woudl love to see answers though.

    flick.

    My teacher would be fine with this.
  • Reply 16 of 20
    Really simple program:



    Try every number from 5 to 5000 where the units digit is either 1 or 6.



    Code:


    #include <stdio.h>



    int main(void) {

    int X0, X1, X2, X3, X4, X5;

    int i;



    for (i=6; i<=5000; i+=5) {

    X0 = i;



    if ((X0 - 1) % 5 != 0) continue;

    X1 = ((4*(X0 - 1)) /5);



    if ((X1 - 1) % 5 != 0) continue;

    X2 = ((4*(X1 - 1))/5);



    if ((X2 - 1) % 5 != 0) continue;

    X3 = ((4*(X2 - 1))/5);



    if((X3 - 1) % 5 != 0) continue;

    X4 = ((4*(X3 - 1))/5);



    if((X4 - 1) % 5 != 0) continue;

    X5 = ((4*(X4))/5);



    if ((X5) % 5 == 0) break;

    }



    if (i > 5000)

    printf("This thing didn't work\

    ");

    else

    printf("Your number is %d\

    ", i);



    return 0;

    }







  • Reply 17 of 20
    yevgenyyevgeny Posts: 1,148member
    Quote:

    Originally posted by trailmaster308

    Im not calling you a jerk by any means, but I work as an AIX admin and I got buddies all over the country and we are always im'ing each other with questions and help. I don't really see how this is any different. My bosses call it "make it happen" and they love me for it!



    That I am perfectly fine with me (unless you are under NDA or have a security clearance for your work).



    This however is a student who is asking for help on his homework. The purpose of homework is to learn how to solve the problem, to develop the ability to apply theory to a specific problem. I think that the workplace is different than the classroom.
  • Reply 18 of 20
    yevgenyyevgeny Posts: 1,148member
    Quote:

    Originally posted by Flick Justice

    My teacher would be fine with this.



    Then it is no problem. It is nothing personal, but I don't want to be doing your homework for you, I want you to do your homework so that you learn how to do it yourself.



    Some of my classmates in college were really good at doing homework "collectively" and getting away with it (such things weren't allowed at my school, but some people did it nonetheless). I always worried that I might wind up at a company of people who got through college the same way and I would wind up doing all the work. Fortunately, such people tend to become consultants (where their natural ability to lie and fudge is a positive job skill) and I became a full time code monkey.
  • Reply 19 of 20
    Quote:

    Originally posted by Yevgeny

    Fortunately, such people tend to become consultants (where their natural ability to lie and fudge is a positive job skill)





    LOL



    I think we hired some of your college buddies at my place of employment.
  • Reply 20 of 20
    yevgenyyevgeny Posts: 1,148member
    Quote:

    Originally posted by trailmaster308

    LOL



    I think we hired some of your college buddies at my place of employment.




    Dang I am really sorry. I meant what I said seriously. Consultants are the people who got through college by lying and stealing. Believe it or not, this really deos prepare them for their job environments. Consultant company interviewers have a spider sense that can pick these people out of a crowd. It is sick.



    My sales experience (something like five years of selling computers face to face/over the phone) made consultant companies go crazy over my resume. I was a geek who had people skills and sales skills. One of the companies (Sapient) actually managed to harrass me into an interview and at the end I said that I couldn't see myself working for them (thanks for your time though). I wanted to write good code and they wanted a chimp in a suit who actually understood code.
Sign In or Register to comment.