Skip to content

Instantly share code, notes, and snippets.

@EDmitry
Last active August 29, 2015 14:18
Show Gist options
  • Save EDmitry/e3582e41556ee0b7ece9 to your computer and use it in GitHub Desktop.
Save EDmitry/e3582e41556ee0b7ece9 to your computer and use it in GitHub Desktop.
import Data.List (inits)
rest :: String -> String -> [(Char, String)]
rest [] _ = []
rest (x:xs) ys = (x, xs ++ ys) : rest xs (x:ys)
permutations :: String -> [String]
permutations [x] = [[x]]
permutations xs = do (x, xs) <- rest xs ""
p <- permutations xs
return (x : p)
checkNumber :: String -> Bool
checkNumber = all (\(i, num) -> read num `mod` i == 0) . zip [1..] . tail . inits
findNumbers = filter checkNumber (permutations "123456789")
@shewu
Copy link

shewu commented Apr 4, 2015

LIST MONAD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment