aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchirvasitua <stuart-little@users.noreply.github.com>2021-02-22 16:54:26 -0500
committerchirvasitua <stuart-little@users.noreply.github.com>2021-02-22 16:54:26 -0500
commit6a8a84ccd0a229ac8e0a74d4b058a1784f439a62 (patch)
tree4e589857ea75d56678b0fea74609c6f60209dbd0
parent2c26164a5a90aa14a19078d845769d3ec9fbb5ae (diff)
downloadperlweeklychallenge-club-6a8a84ccd0a229ac8e0a74d4b058a1784f439a62.tar.gz
perlweeklychallenge-club-6a8a84ccd0a229ac8e0a74d4b058a1784f439a62.tar.bz2
perlweeklychallenge-club-6a8a84ccd0a229ac8e0a74d4b058a1784f439a62.zip
1st commit on 101_haskell
-rwxr-xr-xchallenge-101/stuart-little/haskell/ch-1.hs29
-rwxr-xr-xchallenge-101/stuart-little/haskell/ch-2.hs12
2 files changed, 41 insertions, 0 deletions
diff --git a/challenge-101/stuart-little/haskell/ch-1.hs b/challenge-101/stuart-little/haskell/ch-1.hs
new file mode 100755
index 0000000000..ae87883a60
--- /dev/null
+++ b/challenge-101/stuart-little/haskell/ch-1.hs
@@ -0,0 +1,29 @@
+#!/usr/bin/env runghc
+
+-- run <script> <space-separated array entries>
+
+import Data.List (transpose)
+import Data.List.Extra (minimumOn)
+import Data.List.Utils (join)
+import System.Environment (getArgs)
+import Text.Printf (printf)
+
+rtcc :: [[a]] -> [[a]]
+rtcc = reverse . transpose
+
+pck :: Int -> Int -> [a] -> [[a]]
+pck m n as
+ |m==1 = [as]
+ |n==1 = sequence [reverse as]
+ |otherwise = smlr ++ [take n as] where
+ smlr = rtcc $ pck n (m-1) $ drop n as
+
+rowsToPack :: Int -> Int
+rowsToPack n = minimumOn (\x -> abs (x - (div n x))) $ filter ((==0).(mod n)) [1..(div n 2)]
+
+main = do
+ args <- getArgs
+ let ln = length args
+ m = rowsToPack ln
+ n = div ln m
+ putStrLn $ join "\n" $ map (join " ") $ (map.map) (printf "%5s") $ pck m n args
diff --git a/challenge-101/stuart-little/haskell/ch-2.hs b/challenge-101/stuart-little/haskell/ch-2.hs
new file mode 100755
index 0000000000..9829a3f483
--- /dev/null
+++ b/challenge-101/stuart-little/haskell/ch-2.hs
@@ -0,0 +1,12 @@
+#!/usr/bin/env runghc
+
+-- run <script> <x1 y1 x2 y2 x3 y3>
+
+import System.Environment (getArgs)
+
+areaTr :: Float -> Float -> Float -> Float -> Float -> Float -> Float
+areaTr x1 y1 x2 y2 x3 y3 = flip (/) 2 $ abs $ ((y3-y1)*(x2-x1) - (y2-y1)*(x3-x1))
+
+main = do
+ (x1:y1:x2:y2:x3:y3:_) <- getArgs >>= return . map (read::String->Float)
+ print $ fromEnum $ (areaTr 0 0 x1 y1 x2 y2) + (areaTr 0 0 x2 y2 x3 y3) + (areaTr 0 0 x3 y3 x1 y1) == (areaTr x1 y1 x2 y2 x3 y3)