Skip to content

Instantly share code, notes, and snippets.

@codemonkey-uk
Last active August 29, 2015 14:01
Show Gist options
  • Save codemonkey-uk/bc2a824c55fe16804818 to your computer and use it in GitHub Desktop.
Save codemonkey-uk/bc2a824c55fe16804818 to your computer and use it in GitHub Desktop.
-- 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