diff options
| author | chirvasitua <stuart-little@users.noreply.github.com> | 2021-01-01 10:36:17 -0500 |
|---|---|---|
| committer | chirvasitua <stuart-little@users.noreply.github.com> | 2021-01-01 10:36:17 -0500 |
| commit | 327820d8fa0231274c252ab4955c3ef010b20f34 (patch) | |
| tree | f8b7250a95fbe6c93e383bdd98a2a2392984b927 | |
| parent | 46ad741392d4add09d68ca8ab289a93eadcc475e (diff) | |
| download | perlweeklychallenge-club-327820d8fa0231274c252ab4955c3ef010b20f34.tar.gz perlweeklychallenge-club-327820d8fa0231274c252ab4955c3ef010b20f34.tar.bz2 perlweeklychallenge-club-327820d8fa0231274c252ab4955c3ef010b20f34.zip | |
1st commit on 092_haskell
| -rwxr-xr-x | challenge-092/stuart-little/haskell/ch-1.hs | 17 | ||||
| -rwxr-xr-x | challenge-092/stuart-little/haskell/ch-2.hs | 29 |
2 files changed, 46 insertions, 0 deletions
diff --git a/challenge-092/stuart-little/haskell/ch-1.hs b/challenge-092/stuart-little/haskell/ch-1.hs new file mode 100755 index 0000000000..0eac2a66cc --- /dev/null +++ b/challenge-092/stuart-little/haskell/ch-1.hs @@ -0,0 +1,17 @@ +#!/usr/bin/env runghc + +-- run as <script> <space-separated strings> + +import System.Environment +import Data.List + +freqs :: Ord a => [a] -> [Int] +freqs = (map length).group.sort + +isop x y = ((freqs x == freqs z) && (freqs y == freqs z')) + where z=zip x y + z'=zip y x + +main = do + args <- getArgs + putStrLn $ show $ isop (args !! 0) (args !! 1) diff --git a/challenge-092/stuart-little/haskell/ch-2.hs b/challenge-092/stuart-little/haskell/ch-2.hs new file mode 100755 index 0000000000..20ab23f74f --- /dev/null +++ b/challenge-092/stuart-little/haskell/ch-2.hs @@ -0,0 +1,29 @@ +#!/usr/bin/env runghc + +{- +run as <script> <space-separated interval ends, with the extra interval coming first> + +e.g. <script> 2 6 1 4 8 10 for the first example at + +https://perlweeklychallenge.org/blog/perl-weekly-challenge-092/ +-} + +import System.Environment +import Data.List +import Data.List.Split + +mrg :: Ord a => [a] -> [a] -> [a] +mrg x y = [(min (head x) (head y)), (max (last x) (last y))] + +intp :: Ord a => [a] -> [a] -> Bool +intp x y = ((last y <= last x) && (last y >= head x)) || ((last x <= last y) && (last x >= head y)) + +newintv :: Ord a => [a] -> [[a]] -> [[a]] +newintv x xs = sortOn head (new:old) + where old = filter (not . intp x) xs + new = foldr mrg x $ filter (intp x) xs + +main = do + args <- getArgs + let intEnds = chunksOf 2 (map (read::String->Int) args) + print $ newintv (head intEnds) (tail intEnds) |
