aboutsummaryrefslogtreecommitdiff
path: root/challenge-014
diff options
context:
space:
mode:
authorchirvasitua <stuart-little@users.noreply.github.com>2021-01-13 08:56:30 -0500
committerchirvasitua <stuart-little@users.noreply.github.com>2021-01-13 08:56:30 -0500
commit4cb25c0dbbf4c2d9db16c4c84bad2a66580d8c3d (patch)
treed00a7e6181adec90723b5dec23577abe5d03c774 /challenge-014
parente49b239721f9621482e42d7a88e837b90553570f (diff)
downloadperlweeklychallenge-club-4cb25c0dbbf4c2d9db16c4c84bad2a66580d8c3d.tar.gz
perlweeklychallenge-club-4cb25c0dbbf4c2d9db16c4c84bad2a66580d8c3d.tar.bz2
perlweeklychallenge-club-4cb25c0dbbf4c2d9db16c4c84bad2a66580d8c3d.zip
1st commit on 013,014_haskell
Diffstat (limited to 'challenge-014')
-rwxr-xr-xchallenge-014/stuart-little/haskell/ch-1.hs19
-rwxr-xr-xchallenge-014/stuart-little/haskell/ch-2.hs13
2 files changed, 32 insertions, 0 deletions
diff --git a/challenge-014/stuart-little/haskell/ch-1.hs b/challenge-014/stuart-little/haskell/ch-1.hs
new file mode 100755
index 0000000000..550abe5719
--- /dev/null
+++ b/challenge-014/stuart-little/haskell/ch-1.hs
@@ -0,0 +1,19 @@
+#!/usr/bin/env runghc
+
+-- run <script> <nr of terms>
+
+{-# LANGUAGE PackageImports #-}
+
+import System.Environment (getArgs,)
+import Data.List (elemIndex,)
+import "ghc" Util (nTimes,)
+
+whereSeen :: Int -> [Int] -> Int
+whereSeen x xs = maybe 0 (1+) $ elemIndex x xs
+
+vEckTails :: [[Int]]
+vEckTails = iterate (\l@(h:t) -> (whereSeen h t):l) [0]
+
+main = do
+ nr <- getArgs >>= (return.(read::String->Int).head)
+ print $ reverse $ vEckTails !! (nr -1)
diff --git a/challenge-014/stuart-little/haskell/ch-2.hs b/challenge-014/stuart-little/haskell/ch-2.hs
new file mode 100755
index 0000000000..9c7281c5b3
--- /dev/null
+++ b/challenge-014/stuart-little/haskell/ch-2.hs
@@ -0,0 +1,13 @@
+#!/usr/bin/env runghc
+
+-- run <script> <path-to-dict-file>
+
+import System.Environment (getArgs,)
+import Data.Char (toUpper,)
+import Data.List.Split (chunksOf,)
+import Data.List.Extra (groupSortOn,)
+
+main = do
+ wrds <- getArgs >>= (readFile.head) >>= (return.words)
+ putStrLn $ unwords $ last $ groupSortOn length $ filter (\w-> and $ map (flip elem states) $ chunksOf 2 $ map toUpper w) $ filter (\w -> even (length w) && length w >= 6) wrds where
+ states = ["AL","AK","AZ","AR","CA","CO","CT","DE","DC","FL","GA","HI","ID","IL","IN","IA","KS","KY","LA","ME","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VT","VA","WA","WV","WI","WY"]