Page 3 of 3

Re: Math problems

Posted: June 25th, 2017, 10:38 pm
by Coco
36= 2*3*6 I haven't checked the solution.
So only thing I know is that:
A>1
A <= B
and
B<100
?
A and B are integers.
I don't really have any restrictions here. I've no idea how much is a+b or a*b, nor is there a limit of their sum/product. Doesn't this mean I can just pick any number for their values between 2 and 99 ofcourse?

Re: Math problems

Posted: June 26th, 2017, 6:27 pm
by David
Zaknafein wrote:Here is another similar problem:
https://www.teamten.com/lawrence/puzzles/daughters.html
Here is my solution:
Spoiler: show
Puzzle: A man in my neighborhood has three daughters. One day when I asked their ages he said, “The product of their ages is 36.”
The possible age combinations: 1,1,36; 1,2,18; 1,3,12; 1,4,9; 1,6,6; 2,2,9; 2,3,6; 3,3,4.
When I still couldn’t find their ages he said, “Ok. I’ll give you another clue: the sum of their ages is same as the number of my house.”
The sums of the above listed age combinations: 38, 21, 16, 14, 13, 13, 11, 10.
I knew the number but still couldn’t calculate their ages.
Only 13 appears more than once. So the house number is 13, and the ages are either 1,6,6 or 2,2,9.
So the man gave me a last clue, “My eldest daughter lives upstairs.”
This means that there is a single eldest among them. So only 2,2,9 is possible.
Zaknafein wrote:It can give you a hint about how to solve the previous problem.
Well, they are somewhat similar, but there are too many possibilities in the Susan-and-Paul problem.
Zaknafein wrote:I think you need to make a program to solve it
Yeah, that's what I did.

This is what I came up with in Python (2.7):
Spoiler: show

Code: Select all

from __future__ import unicode_literals, print_function;
import itertools;

# Let 1<a<=b<100 integers.
pairs = [(a,b) for a in xrange(2,100) for b in xrange(a,100)];

# Susan knows S=a+b.
add = lambda (a,b): a + b;
# Paul knows P=ab.
mul = lambda (a,b): a * b;

def sort_and_group(alist, key):
	s = sorted(alist, key=key);
	g = itertools.groupby(s, key=key);
	g = map(lambda (key, iterable): (key, list(iterable)), g);
	return g;

# 1. P: I don't know a and b values.
pairs_1 = sum([P_pairs for (P, P_pairs) in sort_and_group(pairs, mul) if len(P_pairs) >= 2], []);

# 2. S: I knew that you couldn't know that.
pairs_2 = sum([S_pairs for (S, S_pairs) in sort_and_group(pairs, add) if set(S_pairs).issubset(pairs_1)], []);

# 3. P: Now, I know a and b values.
pairs_3 = sum([P_pairs for (P, P_pairs) in sort_and_group(pairs_2, mul) if len(P_pairs) == 1], []);

# 4. S: I also know the values of a and b.
pairs_4 = sum([S_pairs for (S, S_pairs) in sort_and_group(pairs_3, add) if len(S_pairs) == 1], []);

print(pairs_4);
Just for fun, here is the same in SQL (SQLite):
Spoiler: show

Code: Select all

create table N (N int);
insert into N values (2);
-- And so on... A loop would be good, but unfortunately its syntax depends on the database.
insert into N values (99);

-- Let 1<a<=b<100 integers.
-- Susan knows S=a+b.
-- Paul knows P=ab.
create table SP as select a.N as a, b.N as b, a.N+b.N as S, a.N*b.N as P from N as a, N as b where 1 < a and a <= b and b < 100;

-- 1. P: I don't know a and b values.
create table x1 as select * from SP where P in (select P from SP group by P having count(*) >= 2);

-- 2. S: I knew that you couldn't know that.
--create table x2 as select * from SP where S not in (select S from SP where P not in (select P from x1 where x1.S=SP.S) group by S);
create table x2 as select * from SP where S in (select S from SP group by S having count(P) = (select count(P) from x1 where x1.S=SP.S) );

-- 3. P: Now, I know a and b values.
create table x3 as select * from x2 where P in (select P from x2 group by P having count(*) = 1);

-- 4. S: I also know the values of a and b.
create table x4 as select * from x3 where S in (select S from x3 group by S having count(*) = 1);

select * from x4;

Re: Math problems

Posted: June 27th, 2017, 2:41 am
by Coco
Why is 13 showing up twice important? Number of house can be any.
Why there can be only one older than other two, if you say "eldest?"

So, I still don't have a clue for your

Re: Math problems

Posted: June 27th, 2017, 9:40 am
by David
Coco wrote:Why is 13 showing up twice important? Number of house can be any.
The asker in the puzzle says "I knew the number but still couldn’t calculate their ages.".
This means that knowing the sum still does not pick a single age combination.

Here are the possible sums:
1 + 1 + 36 = 38
1 + 2 + 18 = 21
1 + 3 + 12 = 16
1 + 4 + 9 = 14
1 + 6 + 6 = 13
2 + 2 + 9 = 13
2 + 3 + 6 = 11
3 + 3 + 4 = 10

If the house number was 10, for example, then the asker would know that only 3,3,4 is possible, and would not say "still couldn’t calculate their ages".
Coco wrote:Why there can be only one older than other two, if you say "eldest?"
Because the man said "eldest daughter" (singular), not "eldest daughters" (plural).

For me, this is the only interpretation of "my eldest daughter" that allows me to choose between 1,6,6 and 2,2,9.
And I must be able to choose, because the puzzle says "Finally I was able to figure out their ages.".

Re: Math problems

Posted: July 2nd, 2017, 2:15 pm
by Coco
I'm not even going to ask how am I supposed to solve the other problem.

Re: Math problems

Posted: March 4th, 2018, 9:21 pm
by Norbert

Re: Math problems

Posted: March 4th, 2018, 10:13 pm
by Coco
I still have no freakin' idea what was that Zaknafein's problem with a+b and a*b was about. Not that I'm asking for explanation.