Compute the world full symmetry day of JS code, rough version _javascript skills

Source: Internet
Author: User
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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.