aboutsummaryrefslogtreecommitdiff
path: root/challenge-075
diff options
context:
space:
mode:
authorchirvasitua <stuart-little@users.noreply.github.com>2021-01-13 17:48:56 -0500
committerchirvasitua <stuart-little@users.noreply.github.com>2021-01-13 17:48:56 -0500
commitb3c1bc59ab50f50261dee956fdc4581a62465277 (patch)
tree95d7da5106172739f54320a75382624fc9efdfa7 /challenge-075
parente49b239721f9621482e42d7a88e837b90553570f (diff)
downloadperlweeklychallenge-club-b3c1bc59ab50f50261dee956fdc4581a62465277.tar.gz
perlweeklychallenge-club-b3c1bc59ab50f50261dee956fdc4581a62465277.tar.bz2
perlweeklychallenge-club-b3c1bc59ab50f50261dee956fdc4581a62465277.zip
1st commit on 075_haskell
Diffstat (limited to 'challenge-075')
-rw-r--r--challenge-075/stuart-little/README2
-rwxr-xr-xchallenge-075/stuart-little/haskell/ch-1.hs14
-rwxr-xr-xchallenge-075/stuart-little/haskell/ch-2.hs23
3 files changed, 38 insertions, 1 deletions
diff --git a/challenge-075/stuart-little/README b/challenge-075/stuart-little/README
index 76119cbbb8..78439907de 100644
--- a/challenge-075/stuart-little/README
+++ b/challenge-075/stuart-little/README
@@ -1 +1 @@
-Solutions by Stuart Little.
+Solutions by Stuart Little
diff --git a/challenge-075/stuart-little/haskell/ch-1.hs b/challenge-075/stuart-little/haskell/ch-1.hs
new file mode 100755
index 0000000000..317972b84f
--- /dev/null
+++ b/challenge-075/stuart-little/haskell/ch-1.hs
@@ -0,0 +1,14 @@
+#!/usr/bin/env runghc
+
+-- run <script> <target sum> <space-separated coin values>
+
+import System.Environment (getArgs,)
+
+decomps :: (Num a, Ord a) => a -> [a] -> [[a]]
+decomps sum vals
+ |sum==0 =[[]]
+ |otherwise = concat $ map (\val-> map (val:) $ decomps (sum - val) $ filter (val <=) vals) $ filter (sum >=) vals
+
+main = do
+ (sum:coins) <- getArgs >>= return.(map (read::String->Int))
+ mapM_ print $ decomps sum coins
diff --git a/challenge-075/stuart-little/haskell/ch-2.hs b/challenge-075/stuart-little/haskell/ch-2.hs
new file mode 100755
index 0000000000..2dbf1c7c5f
--- /dev/null
+++ b/challenge-075/stuart-little/haskell/ch-2.hs
@@ -0,0 +1,23 @@
+#!/usr/bin/env runghc
+
+-- run <script> <space-separated numbers>
+
+import System.Environment (getArgs,)
+import Data.List (subsequences,)
+
+charTr :: Int -> Int -> Char
+charTr lnr val
+ |val <= lnr = ' '
+ |otherwise = '#'
+
+histLine :: [Int] -> Int -> String
+histLine xs lnr = map (charTr lnr) xs
+
+prettyPrintHist :: [Int] -> [String]
+prettyPrintHist xs = reverse $ map (histLine xs) [0..(maximum xs - 1)]
+
+main = do
+ nrs <- getArgs >>= return.(map (read::String->Int))
+ putStrLn $ (replicate 40 '-') ++ "\nHistogram:\n"
+ mapM_ putStrLn $ prettyPrintHist nrs
+ putStrLn $ (replicate 40 '-') ++ "\nLargest rectangle area: " ++ (show $ maximum $ map (\l-> (length l)*(minimum l)) $ tail $ subsequences nrs) ++ "\n" ++ (replicate 40 '-')