Bonus meta-puzzle: the puzzle as stated is actually unsolvable. Both Sandy and Peter have to know something that the puzzle implies but does not actually stipulate that they know. What is it?
Is it that the other person was told either the sum or the product? Or that the number they were told is the sum or product? edit: After rereading the problem they weren’t told the parameters of the problem or even that they are participating in a puzzle.
“I don't know the numbers”: a math puzzle
31–40 of 119 posts
Re: “I don't know the numbers”: a math puzzle
#32Their code was horrific. My algorithm: import itertools import collections candidates = [s for s in itertools.product(range(100), range(100)) if s[0] (Usually, next step is variable names, comments, etc.)
library(dplyr)
combos
filter(x # Remove dupes
mutate(sum = x + y, prod = x * y)
find_singletons % group_by(!!sym(col)) %>% tally() %>% filter(n == 1)
which(combos[[col]] %in% singletons[[col]])
}
for (i in 1:7) {
# Peter: I don't know the numbers.
combos Re: “I don't know the numbers”: a math puzzle
#33Re: “I don't know the numbers”: a math puzzle
#34Bonus meta-puzzle: the puzzle as stated is actually unsolvable. Both Sandy and Peter have to know something that the puzzle implies but does not actually stipulate that they know. What is it?
Re: “I don't know the numbers”: a math puzzle
#35Their code was horrific. My algorithm: import itertools import collections candidates = [s for s in itertools.product(range(100), range(100)) if s[0] (Usually, next step is variable names, comments, etc.)
My logic was similar, in R: library(dplyr) combos filter(x # Remove dupes mutate(sum = x + y, prod = x * y) find_singletons % group_by(!!sym(col)) %>% tally() %>% filter(n == 1) which(combos[[col]] %in% singletons[[col]]) } for (i in 1:7) { # Peter: I don't know the numbers. combos
- both R and Python; or
- neither R nor Python:
Which of the solutions do you find more readable?
(I have my own opinion, but I'm biased)
Re: “I don't know the numbers”: a math puzzle
#36This isn't quite right. This does find the solution when the problem is well-formed, but it doesn't prove that the solution is valid: if round == 15: for product in products: if len(products[product]) == 1: print('Peter: I do know the numbers') print(products[product][0]) return This should not return - it should continue iterating. If the problem (and the code) is correct, then it should only find one answer - but u…
Re: “I don't know the numbers”: a math puzzle
#37This isn't quite right. This does find the solution when the problem is well-formed, but it doesn't prove that the solution is valid: if round == 15: for product in products: if len(products[product]) == 1: print('Peter: I do know the numbers') print(products[product][0]) return This should not return - it should continue iterating. If the problem (and the code) is correct, then it should only find one answer - but u…
And that's true, the `(i, j)` check is spurious - I blame it on it being throwaway blog post code :)
Re: “I don't know the numbers”: a math puzzle
#38Their code was horrific. My algorithm: import itertools import collections candidates = [s for s in itertools.product(range(100), range(100)) if s[0] (Usually, next step is variable names, comments, etc.)
Re: “I don't know the numbers”: a math puzzle
#39That was a fun puzzle. I have another one that is math puzzle: > You are given two eggs, and access to a 100-storey tower. Both eggs are identical. The aim is to find out the highest floor from which an egg will not break when dropped out of a window from that floor. If an egg is dropped and does not break, it is undamaged and can be dropped again. However, once an egg is broken, that’s it for that egg. > If an egg b…
Quoted post unavailable.
- This is a typical bird's egg. Most insect eggs for instance can survive any fall.
- This is a hard floor, not water, snow,...
- There is nothing to protect the egg.
- Floors are typical ~3m floors, not floors from a doll house.
- The experiment is done on earth
The point of maths is that it doesn't need to be grounded into the world. It is a "if A then B" machine. If A applies to a world then B will apply to that world too, and it will always be the case, it doesn't depend on experimental results.
It is great because scientists, engineers, etc... only have to show (with their experiments and measurements) that A applies to our world, and maths automatically tell them that B applies too, no need for extra experiments and measurements, except for verification.
So in this problem, if you use your "real world" experience with eggs, you only solve the problem for a limited set of preconditions. If you solve it properly, using maths, then it will work in any situation that matches the data of the problem, even for people of Pluto.
Also, if you want to talk "real life", I am not sure a 100 story building exists (there is 101, but exactly 100?). And if that building exists, does it have windows you can drop an egg from at every floor?
Re: “I don't know the numbers”: a math puzzle
#40The algorithm itself is correct, and the answer it arrives at is correct.