diff options
| author | chirvasitua <stuart-little@users.noreply.github.com> | 2021-01-19 17:58:50 -0500 |
|---|---|---|
| committer | chirvasitua <stuart-little@users.noreply.github.com> | 2021-01-19 17:58:50 -0500 |
| commit | 230cf5521f4ca809bb64de2c927f15f5f190393d (patch) | |
| tree | b496ba30c20ab465c799b7beea4069cdf8bf3aa2 | |
| parent | 057e2f8c195bbadaddb5f16467d735ffad9f222a (diff) | |
| download | perlweeklychallenge-club-230cf5521f4ca809bb64de2c927f15f5f190393d.tar.gz perlweeklychallenge-club-230cf5521f4ca809bb64de2c927f15f5f190393d.tar.bz2 perlweeklychallenge-club-230cf5521f4ca809bb64de2c927f15f5f190393d.zip | |
1st commit on 015_haskell
| -rwxr-xr-x | challenge-015/stuart-little/haskell/ch-1.hs | 15 | ||||
| -rwxr-xr-x | challenge-015/stuart-little/haskell/ch-2.hs | 30 |
2 files changed, 45 insertions, 0 deletions
diff --git a/challenge-015/stuart-little/haskell/ch-1.hs b/challenge-015/stuart-little/haskell/ch-1.hs new file mode 100755 index 0000000000..b28f56137d --- /dev/null +++ b/challenge-015/stuart-little/haskell/ch-1.hs @@ -0,0 +1,15 @@ +#!/usr/bin/env runghc + +-- run <script> + +import Data.Numbers.Primes (primes,) +import Data.List (transpose,) + +sprimes = map (\(x:y:z:_) -> y) $ filter (\(x:y:z:_)-> x+z < 2*y) $ transpose $ take 3 $ iterate tail primes + +wprimes = map (\(x:y:z:_) -> y) $ filter (\(x:y:z:_)-> x+z > 2*y) $ transpose $ take 3 $ iterate tail primes + +main = do + let n = 10 + putStrLn ("Strong primes: " ++ (unwords $ map show $ take n sprimes)) + putStrLn ("Weak primes: " ++ (unwords $ map show $ take n wprimes)) diff --git a/challenge-015/stuart-little/haskell/ch-2.hs b/challenge-015/stuart-little/haskell/ch-2.hs new file mode 100755 index 0000000000..ecafca94c8 --- /dev/null +++ b/challenge-015/stuart-little/haskell/ch-2.hs @@ -0,0 +1,30 @@ +#!/usr/bin/env runghc + +-- run <script> <'-e' or '-d' flag tencode or decode respectively> <keyword> <quoted text> + +{-# LANGUAGE PackageImports #-} + +import Data.Char (toUpper,ord,chr,) +import System.Environment (getArgs,) +import "ghc" Util (nTimes,) + +alph :: String +alph = ['A'..'Z'] + +baseOffset :: Int +baseOffset = ord 'A' + +norm :: String -> String +norm = (filter (flip elem alph)) . (map toUpper) + +vigEncode :: String -> String -> String +vigEncode key input = map (\(o,c) -> chr $ baseOffset + (mod (ord c -baseOffset +o) (length alph))) $ zip offsets $ norm input where + offsets = map ((flip (-) baseOffset) . ord) $ cycle $ norm key + +vigDecode :: String -> String -> String +vigDecode key = nTimes (length alph -1) (vigEncode key) + +main = do + (flag:key:txt:_) <- getArgs + let process = if flag == "-d" then vigDecode else vigEncode + putStrLn $ process key txt |
