Last active
August 29, 2015 14:18
-
-
Save EDmitry/e3582e41556ee0b7ece9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
LIST MONAD