Created
September 10, 2011 06:28
-
-
Save bradclawsie/1208013 to your computer and use it in GitHub Desktop.
haskell code to find all such four-digit numbers (except 0000)
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
module Main where | |
import Char | |
f a1 a2 b1 b2 = | |
(a1 == (((a2 + b2 - b1) / 10.0) + b1 - a2) * (-1.0)) && | |
(a2 == ((a2 - a1 - b1) * 10.0) - b2 + b1) && | |
(b1 == (((a2 - a1 - b1) * 10.0) - a2 - b2) * (-1.0)) && | |
(b2 == ((a2 - a1 - b1) * 10) - a2 + b1) | |
-- first line transforms 1978 -> [1.0,9.0,7.0,8.0] | |
g n = let ns = map toRational $ map digitToInt (show n) in | |
f (ns!!0) (ns!!1) (ns!!2) (ns!!3) | |
main = print $ filter g [1000..9999] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment