A math brain teaser

Aug 10, 2001
10,420
2
0
If you know something about modular arithmetic, the following shouldn't be too difficult. If you don't, well, good luck.


Seven children are at a birthday party. A bowl full of jelly beans is distributed equally among the seven children with one jelly bean left over. The leftover jelly bean is fed to Mr. Fluffy. But before any of the children can eat his or her jelly beans, another child arrives at the party. All of the jelly beans are put back into the bowl and redistributed equally among the now eight children. This time there are six jelly beans left over which are consumed by a very happy Mr. Fluffy. Unfortunately a ninth child then arrives at the party, so the jelly beans have to be once again equally distributed among the children. There is again six jelly beans left over. What was the minimum number of jelly beans that could have been in the bowl at the start?
 

Ika

Lifer
Mar 22, 2006
14,264
3
81
22 isn't it.

this isn't going to work with trial and error, will it...? I'm on 43 and the end is nowhere in sight....
 

esun

Platinum Member
Nov 12, 2001
2,214
0
0
Let N be the number of beans.

N = 1 (mod 7)
N - 1 = 6 (mod 8)
N - 7 = 6 (mod 9)

N = 1 (mod 7)
N = 7 (mod 8)
N = 13 = 4 (mod 9)

Chinese Remainder Theorem time! This has a unique solution modulo lcm(7, 8, 9), which is 504. Hence, you can check all numbers 0 through 504 (it's probably easier to write a script for this than for me to go look up the CRT).

My script gives the solution as: 463

EDIT: Here's more info on the CRT in case anyone wants it:

http://en.wikipedia.org/wiki/Chinese_remainder_theorem

The brute force script (Perl)

#!/usr/bin/perl

for $i (0 .. 504) {
if ($i % 7 == 1 && $i % 8 == 7 && $i % 9 == 4) {
print "$i";
}
}


Oops, made a minor error. I only have to go to 503, not to 504. Duh. But since the answer wasn't zero anyway, doesn't matter.
 

ShadowOfMyself

Diamond Member
Jun 22, 2006
4,227
2
0
Probably 22, unless when you say

Unfortunately a ninth child then arrives at the party, so the jelly beans have to be once again equally distributed among the children.

You mean the eight previous had already eaten theirs, and theres eight more, which would make it 30.. But im pretty sure its 22
 

ShadowOfMyself

Diamond Member
Jun 22, 2006
4,227
2
0
Originally posted by: esun
Let N be the number of beans.

N = 1 (mod 7)
N - 1 = 6 (mod 8)
N - 7 = 6 (mod 9)

N = 1 (mod 7)
N = 7 (mod 8)
N = 13 = 4 (mod 9)

Chinese Remainder Theorem time! This has a unique solution modulo lcm(7, 8, 9), which is 504. Hence, you can check all numbers 0 through 504 (it's probably easier to write a script for this than for me to go look up the CRT).

My script gives the solution as: 463

EDIT: Here's more info on the CRT in case anyone wants it:

http://en.wikipedia.org/wiki/Chinese_remainder_theorem

The brute force script (Perl)

#!/usr/bin/perl

for $i (0 .. 504) {
if ($i % 7 == 1 && $i % 8 == 7 && $i % 9 == 4) {
print "$i";
}
}


 

Ika

Lifer
Mar 22, 2006
14,264
3
81
463?

man took me 10 minutes of guessing but i did it by hand.
 

Eeezee

Diamond Member
Jul 23, 2005
9,922
0
0
1+6+6 = 13 jelly beans eaten by the dog
Final number, after 7 are removed, is a 6 plus a multiple of 9, so the formula goes
7+6+9x = 13+9x where x > 0
13+9 = 22 (as a guess)

aaaand it looks like that's wrong
13+9 = 22
22/7 = 3r1 ---now subtract 1 from the total, it was given to the dog
21/8 = 2r5 so it's wrong

13+18 = 31
31/7 = 4r3 so that's wrong
13+27 = 40
40/7 = 5r5 so that's wrong
13+36 = 49
49/7 = 7r0 so that's wrong
58/7 = 8r2 so that's wrong
67/7 = 9r4 so that's wrong
74/7 = 10r4 so that's wrong
83/7 = 11r6 so that's wrong
92/7 = 13r1, 91/8 = 11r3, so that's wrong

Yeah that's enough
 

Ika

Lifer
Mar 22, 2006
14,264
3
81
Originally posted by: LoKe
Who has a party with only 22 jelly beans? Obviously it's 463! :roll: :laugh:

Originally posted by: Aflac
463?

man took me 10 minutes of guessing but i did it by hand.

Shens.

i actually went backwards. I figured out it had to be 9x [even number], then i figured out the even numbers incremented by 8. a little bit of notepad + calculator work and I got the answer.

here's how it went -

hmm, lets try 9x4. plus 6... nope not divisible by 8.

blah blah

lets try 9x18. plus 6... cool, divisible by 8! now lets add another 6... poo, not divisible by 7.

retry blah blah blah

9x50... plus 6... plus 6 again... hell yes divisible by 7! add one more, answer ding ding ding!
 

Born2bwire

Diamond Member
Oct 28, 2005
9,840
6
71
Originally posted by: LoKe
Who has a party with only 22 jelly beans? Obviously it's 463! :roll: :laugh:

Originally posted by: Aflac
463?

man took me 10 minutes of guessing but i did it by hand.

Shens.
You could do it by brute force. That is notice you can solve for two of the conditions easily enough. For example, (x-7) = 8y and (x-13) = 9z OR (x-4) = 9m. So we can say that y = (9m-3)/8. So you can simply continuously add 9 to -3, and watch for multiples of 8 (that is, for a three digit number abc, it is divisible by 8 if ab*2+c is divisible by 8), which you can do in your head. Then when this condition is held, you find x and see if (x-1) is divisible by 7 (for three digit number abc is divisible by 7 if ab-2*c is divisible by 7) which again you can do in your head. This only requires around 50 iterations until you get up to the answer. So it is feasible to do it by hand in 10 minutes. Still, Chinese Remainder Theorem seems to me to be the textbook algorithm for solving this problem.
 

thelanx

Diamond Member
Jul 3, 2000
3,299
0
0
Originally posted by: esun
Let N be the number of beans.

N = 1 (mod 7)
N - 1 = 6 (mod 8)
N - 7 = 6 (mod 9)

N = 1 (mod 7)
N = 7 (mod 8)
N = 13 = 4 (mod 9)

Chinese Remainder Theorem time! This has a unique solution modulo lcm(7, 8, 9), which is 504. Hence, you can check all numbers 0 through 504 (it's probably easier to write a script for this than for me to go look up the CRT).

My script gives the solution as: 463

EDIT: Here's more info on the CRT in case anyone wants it:

http://en.wikipedia.org/wiki/Chinese_remainder_theorem

The brute force script (Perl)

#!/usr/bin/perl

for $i (0 .. 504) {
if ($i % 7 == 1 && $i % 8 == 7 && $i % 9 == 4) {
print "$i";
}
}


Oops, made a minor error. I only have to go to 503, not to 504. Duh. But since the answer wasn't zero anyway, doesn't matter.


Man it has been a while since I really dug into math topics. I kinda miss it, maybe it is time to dig out my old Number Theory book. I really liked that class. Thanks for the reminder.
 

iwantanewcomputer

Diamond Member
Apr 4, 2004
5,045
0
0
Got 463 in excel...took me about 10 min including reading the problem. would have been a little sooner, but i didn't remember how to make if-and statements right

i did one column = number jelly beans, next = mod(n,7) [remainder function], next =mod(n-1,8), next = mod(n-1-6,9) next=if statement where column 2 =1, 3=6, 4=6, and graphed that column
 

nd

Golden Member
Oct 9, 1999
1,690
0
0
I kind of cheated, but this was the fastest way I could come up with to solve it:

> #!/usr/bin/env python
>
> for n in range(8,999,7):
> if (n % 7 == 1) and ((n-1) % 8 == 6) and ((n-7) % 9 == 6):
> print "n = %d" % n

$ ./mod.py
n = 463
n = 967
 

akubi

Diamond Member
Apr 19, 2005
4,392
1
0
you can do it by hand easy

a. x=1 mod 7
b. x=7 mod 8
c. x=4 mod 4

d. a => x=7y+1
e. d&b => 7y = 6(mod 8) => y=2(mod8)
f. e => y=8z+2
g. d&c => 7y = 3 (mod9) => y=3(mod9)
h. g&f => 8z=1(mod9) => z=8(mod9)

so let z=8, then y=66, and x=463
 

Ika

Lifer
Mar 22, 2006
14,264
3
81
I rock, I'm the only one who did guess and check/trial and error.

time wasted ftw!
 
Aug 10, 2001
10,420
2
0
The answer is indeed 463. It's easier to use the substitution method than the Chinese Remainder Theorem. And if the modules had not been relatively prime, the CRT method would have failed.
 

Oscar1613

Golden Member
Jan 31, 2001
1,424
0
0
Originally posted by: Random Variable
The answer is indeed 463. It's easier to use the substitution method than the Chinese Remainder Theorem. And if the modules had not been relatively prime, the CRT method would have failed.

your sig makes baby jesus cry
 
sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |