aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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