Palindrome dates: Difference between revisions

Added Easylang
(Added Easylang)
 
(5 intermediate revisions by 4 users not shown)
Line 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 847 ⟶ 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,542 ⟶ 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,584 ⟶ 2,739:
{{libheader|Wren-fmt}}
{{libheader|Wren-date}}
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
import "./date" for Date
 
var isPalDate = Fn.new { |date|
1,983

edits