module Exercise_12 where import System.IO import Data.List import Data.Ord 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-} a b c = elem c b encrypt d = map fst $ c `filter` f ++ (not . c) `filter` f where f = d `zip` enumFrom 1 c = a (primes $ length d) . snd decrypt c = map fst $ comparing snd `sortBy` (length b `take` c `zip` b ++ length b `drop` c `zip` (filter (not . a b) $ 1 `enumFromTo` length c)) where b = primes $ length c {-TTEW-}