Created
October 26, 2018 06:18
-
-
Save tsvayer/cc9e514fa6bc8ad87170751fe04fab16 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Two perfect logicians, S and P, are told that integers x and y have been chosen such that 1 < x < y and x+y < 100. | |
| # S is given the value x+y and P is given the value xy. They then have the following conversation. | |
| # P: I cannot determine the two numbers. | |
| # S: I knew that. | |
| # P: Now I can determine them. | |
| # S: So can I. | |
| # Given that the above statements are true, what are the two numbers? | |
| require 'prime' | |
| check_sum = ->(x) { (2..x / 2).any? { |a| Prime.prime?(a) && Prime.prime?(x - a) }} | |
| build_variation = ->(x) { (2..x / 2).map { |a| [a * (x - a), x, a] }} | |
| variations = (6..99).reject(&check_sum).flat_map(&build_variation) | |
| variations.select! { |x| variations.count { |y| x[0] == y[0] } == 1 } | |
| variations.select! { |x| variations.count { |y| x[1] == y[1] } == 1 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment