Palindromes

This year on October 2, 2001, the date in MMDDYYYY format will be a palindrome (same forwards as backwards).
10/02/2001
when was the last date that this occurred on?

Comments

  1. // Palindromes For this century (year same forwards as backwards)
    // ex. 10/02/2001

    public static DateTime lastPalindrome() {
    // Last Palindrome
    string P = null;
    // last two digits of the full year
    int year = DateTime.Year.IndexOf(2, 2);


    if (year => 21) {
    // Last PalinD. : 12/02/2021
    P = reverseY(year);
    }
    else if (year => 11) {
    // Last PalinD. : 11/02/2011
    P = reverseY(year);
    }
    else if (year => 01) {
    // Last PalinD. : 10/02/2001
    P = reverseY(year);
    }
    return DateTime.TryParse(P);

    // Reverses the year
    private string reverseY(string yr) {
    return yr.IndexOf(1, 1) + yr.IndexOf(0,1)+ "/" + "02/20" + yr;
    }

    }

    ReplyDelete

Post a Comment

Popular posts from this blog