diff options
| author | chirvasitua <stuart-little@users.noreply.github.com> | 2021-01-23 14:18:39 -0500 |
|---|---|---|
| committer | chirvasitua <stuart-little@users.noreply.github.com> | 2021-01-23 14:18:39 -0500 |
| commit | 9748e015575f076160934c41d1b287d36548334f (patch) | |
| tree | b80114e1d62c2119b75dfdcdbbdc35996c245842 /challenge-027 | |
| parent | 45a9178d4865a7289d6856d7756468f896a04e49 (diff) | |
| download | perlweeklychallenge-club-9748e015575f076160934c41d1b287d36548334f.tar.gz perlweeklychallenge-club-9748e015575f076160934c41d1b287d36548334f.tar.bz2 perlweeklychallenge-club-9748e015575f076160934c41d1b287d36548334f.zip | |
1st commit on 027_haskell
Diffstat (limited to 'challenge-027')
| -rwxr-xr-x | challenge-027/stuart-little/haskell/ch-1.hs | 20 | ||||
| -rwxr-xr-x | challenge-027/stuart-little/haskell/ch-2.hs | 17 |
2 files changed, 37 insertions, 0 deletions
diff --git a/challenge-027/stuart-little/haskell/ch-1.hs b/challenge-027/stuart-little/haskell/ch-1.hs new file mode 100755 index 0000000000..3c99006226 --- /dev/null +++ b/challenge-027/stuart-little/haskell/ch-1.hs @@ -0,0 +1,20 @@ +#!/usr/bin/env runghc + +{- +run <script> <8 space-separated coordinates>; e.g. + +<script> a b c d p q r s will return the intersection between lines +(a,b), (c,d) and +(p,q), (r,s) +-} + +import Data.List.Split (chunksOf,) +import Graphics.Gloss.Geometry.Line (intersectLineLine,) +import System.Environment (getArgs,) + +main = do + (p1:p2:q1:q2:_) <- getArgs >>= return . (map (\[x,y]->(x,y))) . (chunksOf 2) . (map (read::String->Float)) . (take 8) + let inter = intersectLineLine p1 p2 q1 q2 + putStrLn $ case inter of + Nothing -> "No intersection." + Just x -> show x diff --git a/challenge-027/stuart-little/haskell/ch-2.hs b/challenge-027/stuart-little/haskell/ch-2.hs new file mode 100755 index 0000000000..de14a73774 --- /dev/null +++ b/challenge-027/stuart-little/haskell/ch-2.hs @@ -0,0 +1,17 @@ +#!/usr/bin/env runghc + +{- +run <script> and keep entering integer values +-} + +import Data.List.Extra (headDef,) + +mn :: [Int] -> IO () +mn xs = do + putStrLn $ "Last value: " ++ (headDef "none yet" $ map show xs) + putStrLn $ "History: " ++ (show xs) + x <- (readLn::IO Int) + mn (x:xs) + +main :: IO () +main = mn [] |
