aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchirvasitua <stuart-little@users.noreply.github.com>2021-01-01 10:36:17 -0500
committerchirvasitua <stuart-little@users.noreply.github.com>2021-01-01 10:36:17 -0500
commit327820d8fa0231274c252ab4955c3ef010b20f34 (patch)
treef8b7250a95fbe6c93e383bdd98a2a2392984b927
parent46ad741392d4add09d68ca8ab289a93eadcc475e (diff)
downloadperlweeklychallenge-club-327820d8fa0231274c252ab4955c3ef010b20f34.tar.gz
perlweeklychallenge-club-327820d8fa0231274c252ab4955c3ef010b20f34.tar.bz2
perlweeklychallenge-club-327820d8fa0231274c252ab4955c3ef010b20f34.zip
1st commit on 092_haskell
-rwxr-xr-xchallenge-092/stuart-little/haskell/ch-1.hs17
-rwxr-xr-xchallenge-092/stuart-little/haskell/ch-2.hs29
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)