Last active
June 9, 2022 17:31
-
-
Save DanielBlanco/4e259bd9001ddfdf0bc3526de72074ab to your computer and use it in GitHub Desktop.
Las edades de un padre y su hijo suman 66. La edad del padre es la edad del hijo, pero invertida. Cuantos años tienen?
This file contains 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
-- I'm pretty sure the code can be simplified, but for 5mins work is OK :P | |
-- run with calculate(66) | |
ages maxAge = [ (a, b) | a <- [1..maxAge], b <- [1..maxAge] ] | |
calculate :: Integer -> [(Integer, Integer)] | |
calculate sumedAges = filter (valid sumedAges) $ ages sumedAges | |
valid:: Integer -> (Integer, Integer) -> Bool | |
valid sumedAges (x, y) = | |
x > y && y + x == sumedAges && revNum(x) == y | |
revNum = read.reverse.show.(+0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The ages of a father and son add up to 66. The age of the father is the age of the child, but inverted. How old are they?