pandigital.hs (635B)
1 -- Spec: a 3-digit number is added to another 3-digit number, and the result is 2 -- a 4-digit number. If the ten digits involved are all different (0 thru 9) 3 -- then what is the smallest possible value for any of the three numbers? 4 5 import Data.List 6 7 -- nums = [(x, y, x + y) | x <- 8 9 pandigitals = [(x, y, x + y) | x <- shared, y <- shared, x < y, x + y > 999, unique [x, y, x + y]] 10 where shared = filter (unique . return) [100..999] 11 unique = (\x -> x == nub x) . (show =<<) 12 13 unique :: Show a => [a] -> Bool 14 unique = (\x -> x == nub x) . (show =<<) 15 16 -- stringize :: Show a => [a] -> String 17 -- stringize = (show =<<) 18