diff options
| author | chirvasitua <stuart-little@users.noreply.github.com> | 2021-08-16 20:21:20 -0400 |
|---|---|---|
| committer | chirvasitua <stuart-little@users.noreply.github.com> | 2021-08-16 20:21:20 -0400 |
| commit | ca19c82987c3cef338dd9f9ec06eadaba63902a8 (patch) | |
| tree | 6f2bc1fcd8fe1bd6524ce7715bae19adda06affd /challenge-126 | |
| parent | 762eb5d20f41a5e64deb412ab997b91017c24b51 (diff) | |
| download | perlweeklychallenge-club-ca19c82987c3cef338dd9f9ec06eadaba63902a8.tar.gz perlweeklychallenge-club-ca19c82987c3cef338dd9f9ec06eadaba63902a8.tar.bz2 perlweeklychallenge-club-ca19c82987c3cef338dd9f9ec06eadaba63902a8.zip | |
1st commit on 126_haskell
Diffstat (limited to 'challenge-126')
| -rwxr-xr-x | challenge-126/stuart-little/haskell/ch-1.hs | 18 | ||||
| -rwxr-xr-x | challenge-126/stuart-little/haskell/ch-2.hs | 25 |
2 files changed, 43 insertions, 0 deletions
diff --git a/challenge-126/stuart-little/haskell/ch-1.hs b/challenge-126/stuart-little/haskell/ch-1.hs new file mode 100755 index 0000000000..3ad9b0fed8 --- /dev/null +++ b/challenge-126/stuart-little/haskell/ch-1.hs @@ -0,0 +1,18 @@ +#!/usr/bin/env runghc + +-- run <script> <number> + +import Data.Char (digitToInt) +import System.Environment (getArgs) + +no1 :: String -> Integer +no1 nr + |length nr == 0 = 0 + |head nr == '1' = 9^(length nr -1) + |otherwise = ((toInteger $ digitToInt $ head nr) - 1) * 9^(length nr -1) + (no1 $ tail nr) + +adjNo1 :: String -> Integer +adjNo1 nr = if (not $ elem '1' nr) then (no1 nr) else (no1 nr - 1) + +main :: IO () +main = getArgs >>= putStrLn.show.adjNo1.head diff --git a/challenge-126/stuart-little/haskell/ch-2.hs b/challenge-126/stuart-little/haskell/ch-2.hs new file mode 100755 index 0000000000..115b56e33c --- /dev/null +++ b/challenge-126/stuart-little/haskell/ch-2.hs @@ -0,0 +1,25 @@ +#!/usr/bin/env runghc + +-- run <script> + +{-# LANGUAGE QuasiQuotes #-} + +import System.Environment (getArgs) +import Text.RawString.QQ + +nbrs :: [[a]] -> Int -> Int -> [(Int,Int)] +nbrs mat i j = filter (\p-> (fst p /= i || snd p /= j) && (0 <= fst p) && (fst p < length mat) && (0 <= snd p) && (snd p < length (head mat))) $ map (\[x,y]->(i+x,j+y)) $ sequence $ replicate 2 [-1..1] + +mines :: [[String]] -> [[String]] +mines xs = map (map (\(p,q,r)-> if r == "x" then "x" else show $ length $ filter (\nbr-> (xs !! (fst nbr)) !! (snd nbr) == "x") $ nbrs xs p q)) indexed where + indexed = map (\(i,ar)-> map (\(j,x) -> (i,j,x)) $ zip [0..] ar) $ zip [0..] xs + +inptStr :: String +inptStr=[r|x * * * x * x x x x +* * * * * * * * * x +* * * * x * x * x * +* * * x x * * * * * +x * * * x * * * * x|] + +main :: IO () +main = putStrLn $ unlines $ map unwords $ mines $ map words $ lines inptStr |
