diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-02-23 18:51:05 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-23 18:51:05 +0000 |
| commit | ea9afad83aa0dd4aa11db5195c6c8df4d426dd53 (patch) | |
| tree | ae8aa20208c9beb02516af7f87574999793c8a81 | |
| parent | 6966f23352ab1525b44a8c7401cf1d3dac6c7d75 (diff) | |
| parent | 6a8a84ccd0a229ac8e0a74d4b058a1784f439a62 (diff) | |
| download | perlweeklychallenge-club-ea9afad83aa0dd4aa11db5195c6c8df4d426dd53.tar.gz perlweeklychallenge-club-ea9afad83aa0dd4aa11db5195c6c8df4d426dd53.tar.bz2 perlweeklychallenge-club-ea9afad83aa0dd4aa11db5195c6c8df4d426dd53.zip | |
Merge pull request #3609 from stuart-little/stuart-little_101_haskell
1st commit on 101_haskell
| -rwxr-xr-x | challenge-101/stuart-little/haskell/ch-1.hs | 29 | ||||
| -rwxr-xr-x | challenge-101/stuart-little/haskell/ch-2.hs | 12 |
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) |
