How to resolve the algorithm Palindrome dates step by step in the Nim programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Palindrome dates step by step in the Nim programming language
Table of Contents
Problem Statement
Today (2020-02-02, at the time of this writing) happens to be a palindrome, without the hyphens, not only for those countries which express their dates in the yyyy-mm-dd format but, unusually, also for countries which use the dd-mm-yyyy format.
Write a program which calculates and shows the next 15 palindromic dates for those countries which express their dates in the yyyy-mm-dd format.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Palindrome dates step by step in the Nim programming language
Source code in the nim programming language
import strformat, times
func digits(n: int): seq[int] =
var n = n
while n != 0:
result.add n mod 10
n = n div 10
echo "First 15 palindrome dates after 2020-02-02:"
var count = 0
var year = 2021
while count != 15:
let d = year.digits
let monthNum = 10 * d[0] + d[1]
let dayNum = 10 * d[2] + d[3]
if monthNum in 1..12:
if dayNum <= getDaysInMonth(Month(monthNum), year):
# Date is valid.
echo &"{year}-{monthNum:02}-{dayNum:02}"
inc count
inc year
You may also check:How to resolve the algorithm Hash from two arrays step by step in the Mathematica/Wolfram Language programming language
You may also check:How to resolve the algorithm Create a two-dimensional array at runtime step by step in the Groovy programming language
You may also check:How to resolve the algorithm Comma quibbling step by step in the Phix programming language
You may also check:How to resolve the algorithm Minesweeper game step by step in the Raku programming language
You may also check:How to resolve the algorithm Maze generation step by step in the Aime programming language