diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-01-17 22:29:58 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-17 22:29:58 +0000 |
| commit | 9a13cb660e97c6efb285ee804aa8d62dd329174e (patch) | |
| tree | b4e4c5f6d5efee23d369dbdb5bcb141edd9aa7ba | |
| parent | a4da30ec239e6fea2f53752bc20676f27614d5e3 (diff) | |
| parent | aed49f3e9f74bed996d9152544839e0f6d3a153d (diff) | |
| download | perlweeklychallenge-club-9a13cb660e97c6efb285ee804aa8d62dd329174e.tar.gz perlweeklychallenge-club-9a13cb660e97c6efb285ee804aa8d62dd329174e.tar.bz2 perlweeklychallenge-club-9a13cb660e97c6efb285ee804aa8d62dd329174e.zip | |
Merge pull request #3297 from stuart-little/stuart-little_084_haskell
1st commit on 084_haskell
| -rw-r--r-- | challenge-084/stuart-little/README | 2 | ||||
| -rwxr-xr-x | challenge-084/stuart-little/haskell/ch-1.hs | 18 | ||||
| -rwxr-xr-x | challenge-084/stuart-little/haskell/ch-2.hs | 12 |
3 files changed, 31 insertions, 1 deletions
diff --git a/challenge-084/stuart-little/README b/challenge-084/stuart-little/README index 76119cbbb8..78439907de 100644 --- a/challenge-084/stuart-little/README +++ b/challenge-084/stuart-little/README @@ -1 +1 @@ -Solutions by Stuart Little. +Solutions by Stuart Little diff --git a/challenge-084/stuart-little/haskell/ch-1.hs b/challenge-084/stuart-little/haskell/ch-1.hs new file mode 100755 index 0000000000..3a805df5aa --- /dev/null +++ b/challenge-084/stuart-little/haskell/ch-1.hs @@ -0,0 +1,18 @@ +#!/usr/bin/env runghc + +-- run <script> <integer> + +import Data.Int (Int32,) +import System.Environment (getArgs,) + +is32 :: Int -> Bool +is32 n = n <= bd && n >= ((-bd)-1) where + bd = fromIntegral (maxBound::Int32) + +revInt :: Int -> Int +revInt n = if (is32 res) then res else 0 where + res = (*) (signum n) $ (read::String->Int) $ reverse $ show $ abs n + +main = do + nr <- getArgs >>= return.(read::String->Int).head + putStrLn $ show $ revInt nr diff --git a/challenge-084/stuart-little/haskell/ch-2.hs b/challenge-084/stuart-little/haskell/ch-2.hs new file mode 100755 index 0000000000..a320c2d18d --- /dev/null +++ b/challenge-084/stuart-little/haskell/ch-2.hs @@ -0,0 +1,12 @@ +#!/usr/bin/env runghc + +-- run <script> <space-separated 0-1 strings, one string per row> + +import System.Environment (getArgs,) + +countSquares :: Eq a => a -> [[a]] -> Int +countSquares c mat = length $ filter (and.(map (c==))) $ (map.map) (\[p,q]-> mat !! p !! q) $ map (\(x,y,d)-> sequence [[x,x+d],[y,y+d]]) $ [(x,y,d) | [x,y,d] <- sequence $ replicate 3 [0..(min (length mat) (length $ head mat))], 0<d, x+d < length mat, y+d < (length $ head mat) ] + +main = do + mat <- getArgs + print $ countSquares '1' mat |
