aboutsummaryrefslogtreecommitdiff
path: root/challenge-082/jeongoon
diff options
context:
space:
mode:
authorMyoungjin JEON <jeongoon@gmail.com>2020-10-15 16:30:40 +1100
committerMyoungjin JEON <jeongoon@gmail.com>2020-10-15 16:30:40 +1100
commitab98223ab4e3532ea4cc8103ff5a3e9c24f4241d (patch)
treec9908fc3ec28926d861ea28f3fe42180c17fd5de /challenge-082/jeongoon
parente82c1cad04bc5202cdda9f36ccaad78c47cffe98 (diff)
downloadperlweeklychallenge-club-ab98223ab4e3532ea4cc8103ff5a3e9c24f4241d.tar.gz
perlweeklychallenge-club-ab98223ab4e3532ea4cc8103ff5a3e9c24f4241d.tar.bz2
perlweeklychallenge-club-ab98223ab4e3532ea4cc8103ff5a3e9c24f4241d.zip
[ch-082/jeongoon] add ch-1.hs, some more info on ch-2.hs
Diffstat (limited to 'challenge-082/jeongoon')
-rw-r--r--challenge-082/jeongoon/haskell/ch-1.hs23
-rw-r--r--challenge-082/jeongoon/haskell/ch-2.hs6
2 files changed, 28 insertions, 1 deletions
diff --git a/challenge-082/jeongoon/haskell/ch-1.hs b/challenge-082/jeongoon/haskell/ch-1.hs
new file mode 100644
index 0000000000..ccfb0ce0e9
--- /dev/null
+++ b/challenge-082/jeongoon/haskell/ch-1.hs
@@ -0,0 +1,23 @@
+import System.Environment
+import System.Exit
+import Data.Char (isNumber)
+import Data.Maybe (isJust, catMaybes)
+
+{- test with:
+runhaskell ch-1.hs 12 18
+-}
+
+-- from ch-081/ch-1.hs :-]
+--commonDivisors :: (Integral a) => [a] -> [a]
+commonDivisors [] = []
+commonDivisors xs = filter (\cd -> all ((==0).(flip rem) cd) xs) [1..(gcd')]
+ where gcd' = foldr1 (\acc x -> gcd acc x) xs
+
+main = do
+ (catMaybes.map (\nStr ->
+ if (all isNumber nStr) then Just(read nStr :: Int)
+ else Nothing )) `fmap` getArgs
+ >>= (\nums ->
+ if length nums /= 2 then
+ die "Usage: runhaskell ch-1.hs <natural num> <natural num>"
+ else (putStrLn.show.commonDivisors.take 2) nums )
diff --git a/challenge-082/jeongoon/haskell/ch-2.hs b/challenge-082/jeongoon/haskell/ch-2.hs
index a3fc204f5a..5dd2eff3fd 100644
--- a/challenge-082/jeongoon/haskell/ch-2.hs
+++ b/challenge-082/jeongoon/haskell/ch-2.hs
@@ -3,6 +3,10 @@ import System.Exit
import Data.Maybe (catMaybes)
import Data.List (intersect, intercalate)
+{- test with:
+runhaskell ch-2.hs XXY XXZ XXXXZY
+-}
+
data WhichPart = Odd | Even deriving (Show, Eq)
decomposeAsEachOddsEvensWith :: String -> [Int] -> ([String], String, String)
@@ -86,7 +90,7 @@ main = do
args <- getArgs;
let sa = args !! 0; sb = args !! 1; sc = args !! 2 in
if length args /= 3
- then die "Usage: runhaskell ch-1.hs <string A> <string B> <string C>"
+ then die "Usage: runhaskell ch-2.hs <string A> <string B> <string C>"
else
case allInterleavedCases sa sb sc of
Left err -> putStrLn $ "0 as " ++ err