diff options
| -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 [] |
