Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. using System;
  2.  
  3. public static class Kata
  4. {
  5. public static int Reverse(int num)
  6. {
  7. int result = 0;
  8.  
  9. while (num > 0)
  10. {
  11. result = result*10 + num%10;
  12. num /= 10;
  13. }
  14.  
  15. return result;
  16. }
  17.  
  18. public static int palindromeChainLength(int n)
  19. {
  20. if(checkPalindrome(n.ToString()))
  21. return 0;
  22.  
  23. int i = 0;
  24.  
  25. while(!checkPalindrome(n.ToString()))
  26. {
  27. i++;
  28.  
  29. n += Reverse(n);
  30. }
  31.  
  32. return i;
  33. }
  34.  
  35. public static bool checkPalindrome(string n)
  36. {
  37. if(n.Length == 1 || n.Length == 0)
  38. return true;
  39.  
  40. for(int i = 0; i < n.Length ; i++)
  41. if(n[i] != n[n.Length - 1 - i])
  42. return false;
  43.  
  44. return true;
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement