Like 20111102.
Afternoon idle Boring, wrote a, the code has not been optimized,
Just with a boring effort to write out.
If there is any one who is interested in the code optimization, thank you
After calculation in the year 2000 to 3000, a total of 36 eligible world perfect symmetry day.
See some of the blog in the garden, you can add the following "Run", the direct execution of HTML code, do not know how the whole, but someone told
Copy Code code as follows:
<! DOCTYPE html>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title> the palindrome day after 1000 </title>
<script>
/**
* Change the date into a standard 8-bit format, such as 20111102
* Divide it into four segments 20 11 11 02 For centuries, years, months, days
* Annual algorithm time complexity of O (N3), and from the latter four, month-day can be the final results, more efficient
* Because leap year February mantissa is 9, more than the long history of mankind, so no need to consider
*/
;;( function () {
var thedatelist=[];
The greatest value of the century with Palindrome days
var maxforcentury=30;
The minimum value of the century with Palindrome days
var minforcentury=20;
The maximum number of years of palindrome may appear, here only rough treatment
var maxforyear=21;
var maxforday=31;//does not rule out leap year
for (Var i=1;i<=12;i++) {
var stdyear,stdday;
var stdmonth=getstandarddate (i);
/*
if (Getreversedate (stdmonth) >maxforday) {
Continue
}
*/
Maxforday=getdate (i);
for (Var k=1;k<maxforday;k++) {
Stdday =getstandarddate (k);
Stdyear=getreversedate (Stdmonth+stdday);
if (Getreversedate (stdday), parseint) >=minforcentury
&& parseint (Getreversedate (stdday), <maxforcentury)
Thedatelist.push (Stdyear+stdmonth+stdday)
}
}
Thedatelist.sort (); Sort
for (Var i=0;i<thedatelist.length;i++) {
Console.log (Thedatelist[i]);
}
Console.log (' A total of%d records ', thedatelist.length)
/**
* Number of current months based on month
* @param {int} val month
* @return {int}
*/
Function GetDate (val) {
return val%2==0?30:31;
}
/**
* Convert a Date value less than 10 to a standard 8-bit date value
* @param {int} val month or date
* @return {string} standard format
*/
Function Getstandarddate (val) {
if (val<10) {
Return ' 0 ' +val;
}
return val.tostring ();
}
/**
* Reverse Date
* @param the standard format for the date month or date of {string}
* @return {string} reversed standard format
*/
function Getreversedate (date) {
Return Date.split (""). Reverse (). Join ("");
}
})();
</script>
<body>
</body>