Palindrome dates: Difference between revisions

no edit summary
No edit summary
Line 1,515:
9180-08-19 9210-01-29 9221-12-29 9250-05-29 9280-08-29
9190-09-19 9211-11-29 9230-03-29 9260-06-29 9290-09-29
</pre>
 
=={{header|PureBasic}}==
<lang PureBasic>NewList pdates.s()
 
Procedure.b IsLeap(y.i)
ProcedureReturn Bool( y % 4 = 0 ) & Bool( y % 100 <> 0 ) | Bool( y % 400 = 0 )
EndProcedure
 
If OpenConsole("")=0 : End 1 : EndIf
 
For j=2021 To 9999
For m=1 To 12
tm2=28+1*IsLeap(j)
For t=1 To 31
If m=2 And t>tm2 : Break : EndIf
If (m=4 Or m=6 Or m=9 Or m=11) And t>30 : Break : EndIf
s$=Str(j)+RSet(Str(m),2,"0")+RSet(Str(t),2,"0")
If ReverseString(s$)=s$
AddElement(pdates()) : pdates()=Mid(s$,1,4)+"-"+Mid(s$,5,2)+"-"+Mid(s$,7,2)
EndIf
Next t
Next m
Next j
 
PrintN("Count of palindromic dates [2021..9999]: "+Str(ListSize(pdates())))
FirstElement(pdates())
t$="First 15:"
For x=1 To 2
PrintN(~"\n"+t$)
For y=1 To 15 : PrintN(pdates()) : NextElement(pdates()) : Next
t$="Last 15:" : SelectElement(pdates(),ListSize(pdates())-15)
Next
Input() : End</lang>
{{out}}
<pre>Count of palindromic dates [2021..9999]: 284
 
First 15:
2021-12-02
2030-03-02
2040-04-02
2050-05-02
2060-06-02
2070-07-02
2080-08-02
2090-09-02
2101-10-12
2110-01-12
2111-11-12
2120-02-12
2121-12-12
2130-03-12
2140-04-12
 
Last 15:
9170-07-19
9180-08-19
9190-09-19
9201-10-29
9210-01-29
9211-11-29
9220-02-29
9221-12-29
9230-03-29
9240-04-29
9250-05-29
9260-06-29
9270-07-29
9280-08-29
9290-09-29
</pre>
 
164

edits