diff options
| author | chirvasitua <stuart-little@users.noreply.github.com> | 2021-07-05 08:59:51 -0400 |
|---|---|---|
| committer | chirvasitua <stuart-little@users.noreply.github.com> | 2021-07-05 08:59:51 -0400 |
| commit | f01545eb40612c352df921c0808a33fba084a866 (patch) | |
| tree | 3b273b9e1c4182f6b08ad1ab8b0413ab1f88e3a4 | |
| parent | d5f2a0c9f3ee311ab8e8d14f6cb67efbc01250ec (diff) | |
| download | perlweeklychallenge-club-f01545eb40612c352df921c0808a33fba084a866.tar.gz perlweeklychallenge-club-f01545eb40612c352df921c0808a33fba084a866.tar.bz2 perlweeklychallenge-club-f01545eb40612c352df921c0808a33fba084a866.zip | |
1st commit on 120_haskell
| -rwxr-xr-x | challenge-120/stuart-little/haskell/ch-1.hs | 17 | ||||
| -rwxr-xr-x | challenge-120/stuart-little/haskell/ch-2.hs | 14 |
2 files changed, 31 insertions, 0 deletions
diff --git a/challenge-120/stuart-little/haskell/ch-1.hs b/challenge-120/stuart-little/haskell/ch-1.hs new file mode 100755 index 0000000000..1188260d0a --- /dev/null +++ b/challenge-120/stuart-little/haskell/ch-1.hs @@ -0,0 +1,17 @@ +#!/usr/bin/env runghc + +-- run <script> <number> + +import Data.Bits ((.&.)) +import Data.Digits (digits,unDigits) +import Data.List.Split (chunksOf) +import System.Environment (getArgs) + +toByte :: String -> [Int] +toByte nr = padding ++ unPadded where + padding = replicate diff 0 + diff = max 0 $ 8-(length unPadded) + unPadded = digits 2 $ ((read::String->Int) nr) .&. 255 + +main :: IO () +main = getArgs >>= putStrLn.show.(unDigits 2).concat.(map reverse).(chunksOf 2).toByte.head diff --git a/challenge-120/stuart-little/haskell/ch-2.hs b/challenge-120/stuart-little/haskell/ch-2.hs new file mode 100755 index 0000000000..b381de9221 --- /dev/null +++ b/challenge-120/stuart-little/haskell/ch-2.hs @@ -0,0 +1,14 @@ +#!/usr/bin/env runghc + +-- run <script> <time> + +import Data.List.Split (splitOn) +import System.Environment (getArgs) + +angl :: Double -> Double -> Double +angl h m = min rawDiff $ 360-rawDiff where + rawDiff = abs ((fromIntegral (mod (round h) 12)*30) + m/2 - m * 6) + +main = do + [h,m] <- getArgs >>= return . map (read::String->Double) . splitOn ":" . head + putStrLn $ show $ angl h m |
