module Exercise_12 where import Data.List import Data.Set (Set) import System.IO import Control.Monad 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 = fst . unzip . sortOn (not . isPrime . snd) . ap zip (enumFromTo 1 . length) decrypt :: String -> String decrypt = fst . unzip . sortOn snd . ap zip (sortOn (not . isPrime) . enumFromTo 1 . length) {-TTEW-} -- encrypt s = fst . unzip $ sortOn (not . isPrime . snd) $ zip s [1..length s] -- encrypt s = fst $ unzip $ sortOn snd $ zip s $ map (\n -> if isPrime n then n else n+10000) [1..length s] -- sortOn (not . isPrime . snd) zip s [1..length s] --decrypt s = fst $ unzip $ sortOn snd $ zip s $ sortOn (not . isPrime) [1..length s] --decrypt s = fst $ unzip $ sortOn snd $ zip s $ sortOn (not . isPrime) [1..length s] --decrypt s = fst $ unzip $ sortOn snd $ zip s $ primes (length s) ++ filter (not . isPrime) [1..length s] --sortOn (`notElem` ) --[('a',1),('l',2),('o',3),('H',4),('l',5)]