aboutsummaryrefslogtreecommitdiff
path: root/challenge-066
diff options
context:
space:
mode:
authorchirvasitua <stuart-little@users.noreply.github.com>2021-01-08 19:53:04 -0500
committerchirvasitua <stuart-little@users.noreply.github.com>2021-01-08 19:53:04 -0500
commit2b6fdb7b63120dfd15b6b42999792fc5ce62adf9 (patch)
tree95cc7ae68656c9769c0ef49004bd61a2b7bb817a /challenge-066
parent9a4ab6ba9b6b42e3e3bcffdf4744be5ab63b269a (diff)
downloadperlweeklychallenge-club-2b6fdb7b63120dfd15b6b42999792fc5ce62adf9.tar.gz
perlweeklychallenge-club-2b6fdb7b63120dfd15b6b42999792fc5ce62adf9.tar.bz2
perlweeklychallenge-club-2b6fdb7b63120dfd15b6b42999792fc5ce62adf9.zip
1st commit on 066_haskell
Diffstat (limited to 'challenge-066')
-rwxr-xr-xchallenge-066/stuart-little/haskell/ch-1.hs24
-rwxr-xr-xchallenge-066/stuart-little/haskell/ch-2.hs10
2 files changed, 34 insertions, 0 deletions
diff --git a/challenge-066/stuart-little/haskell/ch-1.hs b/challenge-066/stuart-little/haskell/ch-1.hs
new file mode 100755
index 0000000000..d63316b6d7
--- /dev/null
+++ b/challenge-066/stuart-little/haskell/ch-1.hs
@@ -0,0 +1,24 @@
+#!/usr/bin/env runghc
+
+-- run <script> <numerator> <denominator>
+
+import System.Environment (getArgs,)
+import Data.List (partition,)
+import Data.List.Split (chunksOf,)
+import Data.Maybe (fromMaybe,)
+import Control.Monad (liftM,)
+
+divFunny :: Int -> Int -> Maybe Int
+divFunny m n
+ |n==0 =Nothing
+ |m==0 =Just 0
+ |otherwise = let
+ (l1,l2) = partition (((abs n)==).length) $ chunksOf (abs n) [1..abs m]
+ coeff = (signum m) * (signum n)
+ in
+ Just $ coeff*(length l1) + (div (coeff - 1) 2)*(length l2)
+
+main = do
+ args <- getArgs
+ let (num:den:_) = map (read::String->Int) args
+ putStrLn $ fromMaybe "Division by zero" $ liftM show $ divFunny num den
diff --git a/challenge-066/stuart-little/haskell/ch-2.hs b/challenge-066/stuart-little/haskell/ch-2.hs
new file mode 100755
index 0000000000..91e660bc42
--- /dev/null
+++ b/challenge-066/stuart-little/haskell/ch-2.hs
@@ -0,0 +1,10 @@
+#!/usr/bin/env runghc
+
+-- run <script> <number>
+
+import System.Environment (getArgs,)
+
+main = do
+ (nr:_) <- getArgs
+ let nrint = read nr::Int
+ mapM_ putStrLn $ map (\(p:q:_) -> (show p) ++ "^" ++ (show q)) $ filter (\(p:q:_) -> p ^ q == nrint) $ sequence $ replicate 2 [2..(floor $ sqrt $ fromIntegral nrint)]