Skip to content

Instantly share code, notes, and snippets.

@DanielBlanco
Last active June 9, 2022 17:31
Show Gist options
  • Save DanielBlanco/4e259bd9001ddfdf0bc3526de72074ab to your computer and use it in GitHub Desktop.
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?
-- 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)
@DanielBlanco
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment