Guest User

Untitled

a guest
Jul 20th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace EulerPalindrome {
  7. class Program {
  8. static void Main(string[] args) {
  9.  
  10. string test2 = "Anna";
  11.  
  12. Console.WriteLine(test2.RightIndex(1));
  13.  
  14. Console.WriteLine(test2.IsPalindrome());
  15.  
  16. }
  17. }
  18.  
  19. static class Extensions
  20. {
  21.  
  22. public static bool IsPalindrome(this string input)
  23. {
  24. input = input.ToLower();
  25.  
  26. int numberOfComparisons = input.Length/2;
  27. numberOfComparisons.Dump();
  28.  
  29. if (numberOfComparisons < 1)
  30. return false;
  31.  
  32. bool retVal = true;
  33.  
  34. for (int numCompare = 1; numCompare <= numberOfComparisons; numCompare++)
  35. {
  36. input.LeftIndex(numCompare).Dump();
  37. input.RightIndex(numCompare).Dump();
  38. if (input.LeftIndex(numCompare) != input.RightIndex(numCompare))
  39. retVal = false;
  40. }
  41.  
  42. return retVal;
  43. }
  44.  
  45.  
  46. public static string LeftIndex(this string input, int numIndex)
  47. {
  48. return input.Substring(numIndex, 1);
  49. }
  50.  
  51.  
  52. public static string RightIndex(this string input, int numIndex)
  53. {
  54. return input.Substring(input.Length - numIndex, 1);
  55. }
  56.  
  57. }
  58.  
  59.  
  60. }
Add Comment
Please, Sign In to add comment