Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
-- A five digit number minus a four digit number equals 33333,
-- where the nine contributing digits are 1-9, each used only once.
import Data.List
slice start end = take (end - start + 1) . drop start
sliced :: String -> [Int]
sliced s = [read $ slice 0 4 s, read $ slice 5 9 s]
sub :: [Int] -> Int
sub (a:b:_) = a - b
findSolution str = [ x | x <- (map sliced $ permutations str), (sub x) == 33333 ]
main = putStrLn ( show $ findSolution "123456789")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment