aboutsummaryrefslogtreecommitdiff
path: root/challenge-105
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-03-24 06:27:39 +0000
committerGitHub <noreply@github.com>2021-03-24 06:27:39 +0000
commit2d1b42e6b8e062093e547ef07d3c5456dab8b2a5 (patch)
tree38e86d327a5bbddd0706cbe1a7707116fafbb30c /challenge-105
parentf6d6ef4d24932d766e0a938ab24a7f961f0b8072 (diff)
parenta7e6c4eca6c5e02cd847bb32e4fa49a96abdadb2 (diff)
downloadperlweeklychallenge-club-2d1b42e6b8e062093e547ef07d3c5456dab8b2a5.tar.gz
perlweeklychallenge-club-2d1b42e6b8e062093e547ef07d3c5456dab8b2a5.tar.bz2
perlweeklychallenge-club-2d1b42e6b8e062093e547ef07d3c5456dab8b2a5.zip
Merge pull request #3766 from stuart-little/stuart-little_105_haskell
Stuart little 105 haskell
Diffstat (limited to 'challenge-105')
-rwxr-xr-xchallenge-105/stuart-little/haskell/ch-1.hs14
-rwxr-xr-xchallenge-105/stuart-little/haskell/ch-2.hs22
2 files changed, 36 insertions, 0 deletions
diff --git a/challenge-105/stuart-little/haskell/ch-1.hs b/challenge-105/stuart-little/haskell/ch-1.hs
new file mode 100755
index 0000000000..3f1647091f
--- /dev/null
+++ b/challenge-105/stuart-little/haskell/ch-1.hs
@@ -0,0 +1,14 @@
+#!/usr/bin/env runghc
+
+-- run <script> <exponent> <number>
+
+import System.Environment (getArgs)
+
+nthRoot :: Int -> Int -> Double
+nthRoot xp nr = let rootFloor = head $ dropWhile (\x -> (x+1)^xp <= nr) [1..] in
+ if (rootFloor ^ xp == nr) then fromIntegral rootFloor
+ else exp (((log $ fromIntegral nr))/(fromIntegral xp))
+
+main = do
+ (xp:nr:_) <- getArgs >>= return . map (read::String->Int)
+ print $ nthRoot xp nr
diff --git a/challenge-105/stuart-little/haskell/ch-2.hs b/challenge-105/stuart-little/haskell/ch-2.hs
new file mode 100755
index 0000000000..dcfc71a4c2
--- /dev/null
+++ b/challenge-105/stuart-little/haskell/ch-2.hs
@@ -0,0 +1,22 @@
+#!/usr/bin/env runghc
+
+-- run <script> <name>
+
+import Data.Char (toLower,toUpper)
+import System.Environment (getArgs)
+
+ellis :: Char -> String -> String
+ellis c name = (c:"o-") ++ if (c == (toLower $ head name))
+ then (tail name)
+ else (c:"") ++ (tail name)
+
+verse :: String -> String
+verse name = let capName = ((toUpper $ head name):(tail name)) in
+ capName ++ ", " ++ capName ++ ", " ++ (ellis 'b' capName) ++ "\n"
+ ++ "Bonana-fanna " ++ (ellis 'f' capName) ++ "\n"
+ ++ "Fee fi " ++ (ellis 'm' capName) ++ "\n"
+ ++ capName ++ "!"
+
+main = do
+ (name:_) <- getArgs
+ putStrLn $ verse name