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?
// 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; }
Given an integer n, write a function that returns count of trailing zeroes in n!. Examples: Input: n = 5 Output: 1 Factorial of 5 is 20 which has one trailing 0. Input: n = 20 Output: 4 Factorial of 20 is 2432902008176640000 which has 4 trailing zeroes. Input: n = 100 Output: 24
// Palindromes For this century (year same forwards as backwards)
ReplyDelete// 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;
}
}