diff options
| author | chirvasitua <stuart-little@users.noreply.github.com> | 2021-02-15 14:45:44 -0500 |
|---|---|---|
| committer | chirvasitua <stuart-little@users.noreply.github.com> | 2021-02-15 14:45:44 -0500 |
| commit | 2e2d4dcd3669f4944cd360e27cbb662b40df8e0f (patch) | |
| tree | de099b509bbeba4b52e7d96a0d963be39e8ef4c9 | |
| parent | 8f446e972a4866adbb363ac085ccdb8f7041f0b9 (diff) | |
| download | perlweeklychallenge-club-2e2d4dcd3669f4944cd360e27cbb662b40df8e0f.tar.gz perlweeklychallenge-club-2e2d4dcd3669f4944cd360e27cbb662b40df8e0f.tar.bz2 perlweeklychallenge-club-2e2d4dcd3669f4944cd360e27cbb662b40df8e0f.zip | |
1st commit on 100_haskell
| -rwxr-xr-x | challenge-100/stuart-little/haskell/ch-1.hs | 23 | ||||
| -rwxr-xr-x | challenge-100/stuart-little/haskell/ch-2.hs | 16 |
2 files changed, 39 insertions, 0 deletions
diff --git a/challenge-100/stuart-little/haskell/ch-1.hs b/challenge-100/stuart-little/haskell/ch-1.hs new file mode 100755 index 0000000000..9639f363e2 --- /dev/null +++ b/challenge-100/stuart-little/haskell/ch-1.hs @@ -0,0 +1,23 @@ +#!/usr/bin/env runghc + +-- run <script> <time in hh:mm format, followed by am/pm if desired> + +import Data.Char (isDigit,toLower) +import Data.List (isInfixOf) +import Data.List.Split (splitOn) +import System.Environment (getArgs) +import Text.Printf (printf) + +fmTime :: String -> Int -> Int -> String +fmTime mode h m + |isInfixOf "am" $ map toLower mode = (printf "%02d" (mod h 12)) ++ ":" ++ (printf "%02d" m) + |isInfixOf "pm" $ map toLower mode = (printf "%02d" ((mod h 12)+12)) ++ ":" ++ (printf "%02d" m) + |otherwise = (printf "%02d" modh) ++ ":" ++ (printf "%02d" m) ++ mer where + mer = if elem h [0..11] then " am" else " pm" + modh = if elem h [1..12] then h else (mod (h-12) 24) + +main = do + (hh:rest:_) <- getArgs >>= return . splitOn ":" . unwords + let h = (read::String->Int) hh + (m,mode) = (\(x,y) -> ((read::String->Int) x, y)) $ span isDigit rest + putStrLn $ fmTime mode h m diff --git a/challenge-100/stuart-little/haskell/ch-2.hs b/challenge-100/stuart-little/haskell/ch-2.hs new file mode 100755 index 0000000000..2dc7a433d1 --- /dev/null +++ b/challenge-100/stuart-little/haskell/ch-2.hs @@ -0,0 +1,16 @@ +#!/usr/bin/env runghc + +-- run <script> <space-separated array entries, right-to-left and top-to-bottom> + +import Data.List.Split (splitPlaces) +import System.Environment (getArgs) + +redStep :: (Num a, Ord a) => [a] -> [a] -> [a] +redStep row1@(h:rest) = zipWith (+) ((h:(zipWith min row1 rest)) ++ [last row1]) + +collapseTriang :: (Num a, Ord a) => [[a]] -> a +collapseTriang = minimum . foldl1 redStep + +main = do + nrs <- getArgs >>= return . map (read::String->Int) + print $ collapseTriang $ splitPlaces [1..] nrs |
