Skip to content

Instantly share code, notes, and snippets.

@bradclawsie bradclawsie/ubs.hs
Created Sep 10, 2011

Embed
What would you like to do?
haskell code to find all such four-digit numbers (except 0000)
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
You can’t perform that action at this time.