module Exercise_12 where import Data.List import Data.Bifoldable import Control.Arrow isPrime :: Int -> Bool isPrime n | n <= 1 = False | otherwise = primeAux (n-1) where primeAux 1 = True primeAux i = n `mod` i /= 0 && primeAux (i-1) -- returns all primes up to the passed number primes :: Int -> [Int] primes n = [i | i<-[2..n], isPrime i] {-WETT-} encrypt :: String -> String encrypt = map snd <<< biconcat <<< partition (isPrime .fst) <<< zip (enumFrom 1) decrypt :: String -> String decrypt = map snd <<< sortOn fst <<< zip =<< biconcat . partition isPrime . enumFromTo 1 . length {-TTEW-} {-MCCOMMENT decrypt = head . ap (filter . (.encrypt) . isPrefixOf) permutations why am i wasting my life with this? i have to learn for exams -}