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