Palindrome dates: Difference between revisions
Content added Content deleted
m (→{{header|Haskell}}: Tidied.) |
|||
Line 1,145: | Line 1,145: | ||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
<syntaxhighlight lang="haskell">import Data. |
<syntaxhighlight lang="haskell">import Data.List (unfoldr) |
||
import Data.List.Split (chunksOf) |
import Data.List.Split (chunksOf) |
||
⚫ | |||
import Data.Tuple (swap) |
|||
import Data.Bool (bool) |
|||
import Data.Maybe (mapMaybe) |
import Data.Maybe (mapMaybe) |
||
import Data.Time.Calendar (Day, fromGregorianValid) |
|||
⚫ | |||
-------------------- PALINDROMIC DATES ------------------- |
|||
palinDates :: [Day] |
palinDates :: [Day] |
||
Line 1,158: | Line 1,159: | ||
palinDay y = fromGregorianValid y m d |
palinDay y = fromGregorianValid y m d |
||
where |
where |
||
[m, d] = unDigits <$> chunksOf 2 |
[m, d] = unDigits <$> chunksOf 2 |
||
⚫ | |||
⚫ | |||
⚫ | |||
unfoldr ((flip bool Nothing . Just . swap . flip quotRem 10) <*> (0 ==)) |
|||
⚫ | |||
⚫ | |||
--------------------------- TEST ------------------------- |
|||
main :: IO () |
main :: IO () |
||
main = |
main = |
||
let n = length palinDates |
let n = length palinDates |
||
putStrLn |
in putStrLn ("Count of palindromic dates [2021..9999]: " |
||
<> show n) >> |
|||
putStrLn "\nFirst 15:" |
putStrLn "\nFirst 15:" >> |
||
mapM_ print |
mapM_ print (take 15 palinDates) >> |
||
putStrLn "\nLast 15:" |
putStrLn "\nLast 15:" >> |
||
mapM_ print |
mapM_ print (take 15 (drop (n - 15) palinDates)) |
||
------------------------- GENERIC ------------------------ |
|||
⚫ | |||
reversedDecimalDigits = unfoldr go |
|||
where |
|||
go n |
|||
| 0 < n = Just $ swap (quotRem n 10) |
|||
| otherwise = Nothing |
|||
⚫ | |||
⚫ | |||
{{Out}} |
{{Out}} |
||
<pre>Count of palindromic dates [2021..9999]: 284 |
<pre>Count of palindromic dates [2021..9999]: 284 |