diff options
| author | chirvasitua <stuart-little@users.noreply.github.com> | 2021-01-15 16:31:08 -0500 |
|---|---|---|
| committer | chirvasitua <stuart-little@users.noreply.github.com> | 2021-01-15 16:31:08 -0500 |
| commit | ca6914a3f829d380093d734e7a3d6c7b6f262f13 (patch) | |
| tree | 1a25c73b54b591331bdffed294aef9966b9217bb /challenge-034 | |
| parent | cd6c653837dc0099b652ddba92cacb8e89b979d6 (diff) | |
| download | perlweeklychallenge-club-ca6914a3f829d380093d734e7a3d6c7b6f262f13.tar.gz perlweeklychallenge-club-ca6914a3f829d380093d734e7a3d6c7b6f262f13.tar.bz2 perlweeklychallenge-club-ca6914a3f829d380093d734e7a3d6c7b6f262f13.zip | |
1st commit on 034_haskell
Diffstat (limited to 'challenge-034')
| -rwxr-xr-x | challenge-034/stuart-little/haskell/ch-1.hs | 18 | ||||
| -rwxr-xr-x | challenge-034/stuart-little/haskell/ch-2.hs | 13 |
2 files changed, 31 insertions, 0 deletions
diff --git a/challenge-034/stuart-little/haskell/ch-1.hs b/challenge-034/stuart-little/haskell/ch-1.hs new file mode 100755 index 0000000000..d0b68b1e27 --- /dev/null +++ b/challenge-034/stuart-little/haskell/ch-1.hs @@ -0,0 +1,18 @@ +#!/usr/bin/env runghc + +-- run <script> + +import Data.List (sort,) +import System.Random (StdGen,newStdGen,randomRs,) +import System.Random.Shuffle (shuffle',) + +main = do + let l=20 + gen <- newStdGen + let lst = shuffle' [1..l] l gen + putStrLn $ "\nInitial list: \n" ++ (unwords $ map show lst) + gen <- newStdGen + let (ilow:ihigh:_) = sort $ take 2 $ randomRs (0,l-1) gen + putStrLn $ "\nSlice between indices " ++ (show ilow) ++ " and " ++ (show ihigh) ++ ":" + putStrLn $ unwords $ map show $ map (lst!!) [ilow..ihigh] + diff --git a/challenge-034/stuart-little/haskell/ch-2.hs b/challenge-034/stuart-little/haskell/ch-2.hs new file mode 100755 index 0000000000..71ed3e3af3 --- /dev/null +++ b/challenge-034/stuart-little/haskell/ch-2.hs @@ -0,0 +1,13 @@ +#!/usr/bin/env runghc + +-- run <script> <two integers separated by arithmetic operator surrounded by whitespace> + +import Data.Function (on,) +import Data.Maybe (fromJust,) +import System.Environment (getArgs,) + +main = do + (nr1:op:nr2:_) <- getArgs + let dsptch :: [(String,Float -> Float -> Float)] + dsptch = zip (map (\x->[x]) "+-*/") [(+),(-),(*),(/)] + putStrLn $ "Result: " ++ (show $ ((fromJust (lookup op dsptch)) `on` (read::String->Float)) nr1 nr2) |
