How to resolve the algorithm Palindrome dates step by step in the Action! programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Palindrome dates step by step in the Action! 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 Action! programming language
Source code in the action! programming language
TYPE Date=[
INT year
BYTE month
BYTE day]
BYTE FUNC IsLeapYear(INT y)
IF y MOD 100=0 THEN
IF y MOD 400=0 THEN
RETURN (1)
ELSE
RETURN (0)
FI
FI
IF y MOD 4=0 THEN
RETURN (1)
FI
RETURN (0)
BYTE FUNC GetMaxDay(INT y BYTE m)
BYTE ARRAY MaxDay=[31 28 31 30 31 30 31 31 30 31 30 31]
IF m=2 AND IsLeapYear(y)=1 THEN
RETURN (29)
FI
RETURN (MaxDay(m-1))
PROC NextDay(Date POINTER d)
BYTE maxD
d.day==+1
maxD=GetMaxDay(d.year,d.month)
IF d.day>maxD THEN
d.day=1
d.month==+1
IF d.month>12 THEN
d.month=1
d.year==+1
FI
FI
RETURN
BYTE FUNC IsPalindrome(Date POINTER d)
INT y
y=d.year
IF y/1000#d.day MOD 10 THEN
RETURN (0)
FI
y==MOD 1000
IF y/100#d.day/10 THEN
RETURN (0)
FI
y==MOD 100
IF y/10#d.month MOD 10 THEN
RETURN (0)
FI
y==MOD 10
IF y#d.month/10 THEN
RETURN (0)
FI
RETURN (1)
PROC PrintB2(BYTE x)
IF x<10 THEN
Put('0)
FI
PrintB(x)
RETURN
PROC PrintDateShort(Date POINTER d)
PrintI(d.year) Put('-)
PrintB2(d.month) Put('-)
PrintB2(d.day)
RETURN
PROC Main()
BYTE count
Date d
count=0
d.year=2020 d.month=2 d.day=3
WHILE count<15
DO
IF IsPalindrome(d) THEN
PrintDateShort(d) PutE()
count==+1
FI
NextDay(d)
OD
RETURN
You may also check:How to resolve the algorithm Attractive numbers step by step in the Maxima programming language
You may also check:How to resolve the algorithm Shoelace formula for polygonal area step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm CRC-32 step by step in the Visual Basic .NET programming language
You may also check:How to resolve the algorithm Catalan numbers step by step in the PHP programming language
You may also check:How to resolve the algorithm Combinations step by step in the Lambdatalk programming language