Thread: Help!? What should I do?

  1. #1
    Registered User
    Join Date
    Dec 2012

    Help!? What should I do?

    Hi! I have a problem here and I don't know where to start. Please help me. Thanks

    Here's the problem..

    You, and two friends, have been hired by a computer firm to clean up their office of all their unused diskettes. These are hidden in various desk drawers and must be collected together into a large pile. As a reward these diskettes are to be divided up equally between you and your friends to take home. How many diskettes were there to start with if the following is true? (There is more than one answer to the puzzle.)

    While everybody was out at coffee, one of your friends sneaks into the room, divides up the diskettes into three equal piles, hides one of the piles and puts the others back into the original pile. There was one diskette left over after the division (ruined by virus), which was thrown away.

    At the next coffee break, the other friend came along, splits the new pile into 3 and hides his share. Again there was one left over (virus killed) which was thrown away. The others were piled back together.

    At the end of the day, all the diskettes that were left in the pile were split up equally amongst you and your friends, and again there was one left over, killed by virus.

    - the judge will input a guess of how many diskettes there were in the original pile

    - The program must determine if that guess (or one of the next 10 numbers above it) satisfies the puzzle given above. If one of the numbers in the range satisfies the puzzle, print how many diskettes everybody gets to take home.


    Number: 6
    No valid number in the range 6 - 16

    Again (y/n): Y

    Number: 48
    Valid starting number: 52
    Friend 1: 24 Friend 2: 18 Me: 7 Virus: 3

    Again (y/n): N

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Well it starts by doing some drawing on paper to try and figure out the underlying maths of the problem.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2012
    The user inputs a guess. You then follow through the instructions, in sequence, translating them to code. If at any point you are required to do the impossible, like taking one diskette from a pile of zero, then you know that the guess is invalid. If you complete all the steps, then the guess is valid.
    It's then trivial to write a loop to check ten guesses.
    I'm the author of MiniBasic: How to write a script interpreter and Basic Algorithms
    Visit my website for lots of associated C programming resources.

  4. #4
    Registered User
    Join Date
    Mar 2010
    Hahaha -- they're not your friends if they're stealing you hard earned diskettes!

    Anyway - I think the point is each time your friends go on the rob, and when you get your bit, the pile is split into 3 and has 1 left over. The pile is reduced each time. So the idea is to check that each of the times the pile is divided into 3 it has 1 spare disk.

    So to program this you need to do a bit of arithmetic and track the results (as you need to print how many disks each person got).

    You can figure out quotients and remainders with divide / and modulus % operators, or use div - C++ Reference
    There's nothing here that's difficult to code. The only bit of advice I'll give you is: don't be tempted into thinking you should use floating point variables for the divisions. If you're dealing in intrinsically integer quantities (there's no mention of snapping diskettes into little bits....) then use integer arithmetic.

Popular pages Recent additions subscribe to a feed