Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public static class Kata
- {
- public static int Reverse(int num)
- {
- int result = 0;
- while (num > 0)
- {
- result = result*10 + num%10;
- num /= 10;
- }
- return result;
- }
- public static int palindromeChainLength(int n)
- {
- if(checkPalindrome(n.ToString()))
- return 0;
- int i = 0;
- while(!checkPalindrome(n.ToString()))
- {
- i++;
- n += Reverse(n);
- }
- return i;
- }
- public static bool checkPalindrome(string n)
- {
- if(n.Length == 1 || n.Length == 0)
- return true;
- for(int i = 0; i < n.Length ; i++)
- if(n[i] != n[n.Length - 1 - i])
- return false;
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement