Palindrome dates: Difference between revisions

Added Easylang
(Added Easylang)
 
(9 intermediate revisions by 7 users not shown)
Line 561:
 
=={{header|BASIC}}==
 
{{works with|QBasic}}
==={{header|BASIC256}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vb">
dateTest = ""
mes = 0 : dia = 0 : anno = 0 : Pal = 0
total = 0
print "Siguientes 15 fechas palindrómicas al 2020-02-02:"
for anno = 2021 to 9999
dateTest = ltrim(string(anno))
for mes = 1 to 12
if mes < 10 then dateTest = dateTest + "0"
dateTest = dateTest + ltrim(string(mes))
for dia = 1 to 31
if mes = 2 and dia > 28 then exit for
if (mes = 4 or mes = 6 or mes = 9 or mes = 11) and dia > 30 then exit for
if dia < 10 then dateTest = dateTest + "0"
dateTest = dateTest + ltrim(string(dia))
for Pal = 1 to 4
if mid(dateTest, Pal, 1) <> mid(dateTest, 9 - Pal, 1) then exit for
next Pal
if Pal = 5 then
total += 1
if total <= 15 then print left(dateTest,4);"-";mid(dateTest,5,2);"-";right(dateTest,2)
end if
if total > 15 then exit for : exit for : exit for
dateTest = left(dateTest, 6)
next dia
dateTest = left(dateTest, 4)
next mes
dateTest = ""
next anno
end
</syntaxhighlight>
{{out}}
<pre>
Igual que la entrada de FreeBASIC.
</pre>
 
==={{header|QBasic}}===
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
{{trans|FreeBASIC}}
<syntaxhighlight lang="basic">
Line 595 ⟶ 636:
NEXT anno
END
</syntaxhighlight>
{{out}}
<pre>
Igual que la entrada de FreeBASIC.
</pre>
 
==={{header|BASIC256}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="lb">
dateTest = ""
mes = 0 : dia = 0 : anno = 0 : Pal = 0
total = 0
print "Siguientes 15 fechas palindrómicas al 2020-02-02:"
for anno = 2021 to 9999
dateTest = ltrim(string(anno))
for mes = 1 to 12
if mes < 10 then dateTest = dateTest + "0"
dateTest = dateTest + ltrim(string(mes))
for dia = 1 to 31
if mes = 2 and dia > 28 then exit for
if (mes = 4 or mes = 6 or mes = 9 or mes = 11) and dia > 30 then exit for
if dia < 10 then dateTest = dateTest + "0"
dateTest = dateTest + ltrim(string(dia))
for Pal = 1 to 4
if mid(dateTest, Pal, 1) <> mid(dateTest, 9 - Pal, 1) then exit for
next Pal
if Pal = 5 then
total += 1
if total <= 15 then print left(dateTest,4);"-";mid(dateTest,5,2);"-";right(dateTest,2)
end if
if total > 15 then exit for : exit for : exit for
dateTest = left(dateTest, 6)
next dia
dateTest = left(dateTest, 4)
next mes
dateTest = ""
next anno
end
</syntaxhighlight>
{{out}}
Line 802 ⟶ 805:
<pre>
Next 15 palindrome dates:
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
</pre>
 
===Using C++20===
<syntaxhighlight lang="c++">
#include <algorithm>
#include <chrono>
#include <iostream>
#include <sstream>
 
bool is_palindrome(const std::chrono::sys_days& date) {
std::ostringstream stream;
stream << date;
std::string date_string = stream.str();
 
date_string.erase(std::remove(date_string.begin(), date_string.end(), '-'), date_string.end());
std::string original = date_string;
std::reverse(date_string.begin(), date_string.end());
 
return date_string == original;
}
 
int main() {
std::chrono::year_month_day date{std::chrono::year{2020}, std::chrono::month{02}, std::chrono::day{02}};
std::chrono::sys_days current_date = std::chrono::sys_days(date);
 
std::cout << "The first 15 palindrome dates after 2020-02-02 are:" << std::endl;
int32_t count = 0;
while ( count < 15 ) {
current_date += std::chrono::days{1};
if ( is_palindrome(current_date) ) {
std::cout << current_date << std::endl;
count++;
}
}
}
</syntaxhighlight>
{{ out }}
<pre>
The first 15 palindrome dates after 2020-02-02 are:
2021-12-02
2030-03-02
Line 844 ⟶ 901:
("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")
</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
 
<syntaxhighlight lang="Delphi">
procedure ShowPalindromeDate(Memo: TMemo);
var DT: TDateTime;
var S,S2: string;
var I,Cnt: integer;
begin
Cnt:=0;
DT:=EncodeDate(2020,02,02);
for I:=0 to High(integer) do
begin
S:=FormatDateTime('yyyymmdd',DT);
S2:=ReverseString(S);
if S=S2 then
begin
Inc(Cnt);
Memo.Lines.Add(IntToStr(Cnt)+' '+FormatDateTime('yyyy-mm-dd',DT));
if Cnt>15 then break;
end;
DT:=DT+1;
end;
end;
 
</syntaxhighlight>
{{out}}
<pre>
1 2020-02-02
2 2021-12-02
3 2030-03-02
4 2040-04-02
5 2050-05-02
6 2060-06-02
7 2070-07-02
8 2080-08-02
9 2090-09-02
10 2101-10-12
11 2110-01-12
12 2111-11-12
13 2120-02-12
14 2121-12-12
15 2130-03-12
16 2140-04-12
Elapsed Time: 44.090 ms.
 
</pre>
 
 
=={{header|EasyLang}}==
<syntaxhighlight>
t = 1580641200
print "First 15 palindrome dates after 2020-02-02 are:"
repeat
t += 86400
a$ = timestr t
a$[] = strchars substr a$ 1 4 & substr a$ 6 2 & substr a$ 9 2
for i = 1 to 4
if a$[i] <> a$[9 - i]
break 1
.
.
if i = 5
cnt += 1
print substr a$ 1 10
.
until cnt = 15
.
</syntaxhighlight>
 
=={{header|F_Sharp|F#}}==
Line 1,222 ⟶ 1,351:
9280-08-29
9290-09-29</pre>
 
=={{header|J}}==
Using J's [[j:Standard_Library/dates|date routines]]:
<syntaxhighlight lang=J>task=: {{
r=. ''
days=. todayno 2020 02 02
while. 15 > #r do.
days=. ({:days)+1+i.1e4
r=. r, days#~(-:|.)"1":,.1 todate days
end.
15 10{.isotimestamp todate r
}}</syntaxhighlight>
 
<syntaxhighlight lang=J> task''
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
</syntaxhighlight>
 
=={{header|Java}}==
Line 1,509 ⟶ 1,668:
2190-09-12
</pre>
 
=={{header|Lua}}==
<syntaxhighlight lang="lua">
 
local year = 2020
for i=1, 15 do
local dateS
repeat
year = year+1
local yearS = tostring(year)
local monthS, dayS = yearS:reverse():match"^(%d%d)(%d%d)$"
local monthN, dayN = tonumber(monthS), tonumber(dayS)
dateS = yearS.."-"..monthS.."-"..dayS
until
monthN>0 and monthN<=12 -- real month
and dayN<32 -- possible day
and os.date( -- real date check
-- be aware that this check is unnecessary because it only affects the 13th century
"%Y-%m-%d"
,os.time{
year = year
,month = monthN
,day = dayN
}
) == dateS
print(dateS)
end
 
</syntaxhighlight>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
Line 2,280 ⟶ 2,468:
{{works with|Halcyon Calc|4.2.7}}
≪ DUP 100 MOD 4 400 IFTE MOD NOT ≫
‘LEAP‘'''LEAP?'''’ STO
≪ 100 + →STR 2 3 SUB ≫
‘→2STR’‘'''→2STR'''’ STO
≪ STR→ → mm dd yy
Line 2,290 ⟶ 2,478:
THEN
{ 31 28 31 30 31 30 31 31 30 31 30 31 }
IF yy '''LEAP?''' THEN 2 29 PUT END
mm GET dd ≥ AND dd 1 ≥ AND
END
≫ ≫
‘DTOK‘'''DTOK?'''’ STO
≪ →STR → year
≪ year 4 DUP SUB year 3 DUP SUB + STR→
year 2 DUP SUB year 1 DUP SUB + STR→
IF DUP2 year '''DTOK?'''
THEN year "-" + ROT '''→2STR''' + "-" + SWAP '''→2STR''' +
ELSE DROP2 ""
END
≫ ≫
‘PALDT’‘'''PALDT'''’ STO
 
≪ { } 2023
WHILE OVER SIZE 15 < REPEAT
DUP '''PALDT'''
IF DUP "" ≠ THEN ROT SWAP + SWAP ELSE DROP END
1 +
Line 2,551 ⟶ 2,739:
{{libheader|Wren-fmt}}
{{libheader|Wren-date}}
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
import "./date" for Date
 
var isPalDate = Fn.new { |date|
2,063

edits