 # I need help with this programing question

A jar of Halloween candy contains an unknown amount of candy and if you can guess exactly how much candy is in the bowl, then you win all the candy. You ask the person in charge the following: If the candy is divided evenly among 5 people, how many pieces would be left over? The answer is 2 pieces. You then ask about dividing the candy evenly among 6 people, and the amount left over is 3 pieces. Finally, you ask about dividing the candy evenly among 7 people, and the amount left over is 2 pieces. By looking at the bowl, you can tell that there are less than 200 pieces. Write a program to determine how many pieces are in the bowl.
(I spent a lot of time on this question and couldn’t make any progress, Can someone please help?)

What have you considered so far, do you have any code written? If you’d want to find that number by hand, what steps would be necessary?

No. I’m completely lost on this question.

Just had a quick read and this is how I would go about it. Start with 200 and divide it by 5,6 and 7. Then get the remainder (%) of these. If the remainder matches up with 2,3,2 then that should give you the answer. If they do not match up try again with 199

1 Like

So starting from the beginning - how do you understand it? Without having specific answer yet, what is needed to find, calculate?

Let’s strip away the clutter - what are we looking for?

• An unknown number.

What do we know?

• The number is between 0 and 200.
• If divided by 5, 6 and 7, we know the left overs
• This is calculated via `number%5`

That’s all we know.
Write a program, that goes through the conditions.
The assumption is, that this will result in exactly one solution.

Don’t try to find a clever solution or get some amazing insight. You are given that the number is less than 200. This hints that you just check ALL NUMBERS below that via program - a brute-force approach.

Thank you so much! …

Thanks! ,… …