diff options
| -rwxr-xr-x | challenge-044/stuart-little/haskell/ch-1.hs | 6 | ||||
| -rwxr-xr-x | challenge-044/stuart-little/haskell/ch-2.hs | 16 |
2 files changed, 22 insertions, 0 deletions
diff --git a/challenge-044/stuart-little/haskell/ch-1.hs b/challenge-044/stuart-little/haskell/ch-1.hs new file mode 100755 index 0000000000..15edf3a4df --- /dev/null +++ b/challenge-044/stuart-little/haskell/ch-1.hs @@ -0,0 +1,6 @@ +#!/usr/bin/env runghc + +-- run <script> + +main = do + putStrLn $ "123-45-67+89=" ++ (show $ 123-45-67+89) diff --git a/challenge-044/stuart-little/haskell/ch-2.hs b/challenge-044/stuart-little/haskell/ch-2.hs new file mode 100755 index 0000000000..b75885bfab --- /dev/null +++ b/challenge-044/stuart-little/haskell/ch-2.hs @@ -0,0 +1,16 @@ +#!/usr/bin/env runghc + +-- run <script> <number to get or nothing to default to 200> + +import Data.List.Extra (headDef,) +import System.Environment (getArgs,) + +doubleOrAdd1 :: Int -> [Int] +doubleOrAdd1 nr + |nr==1 =[1] + |even nr = nr:(doubleOrAdd1 $ div nr 2) + |odd nr = nr:(doubleOrAdd1 $ (-) nr 1) + +main = do + nr <- getArgs >>= return.(read::String->Int).(headDef "200") + print $ reverse $ doubleOrAdd1 nr |
