public static void Main() { bool isGameRunning = true; Console.WriteLine("Palindromes!"); Console.WriteLine("They're words that look the same, whether you read them backwards or forwards!"); while (isGameRunning) { Console.WriteLine("Enter a word, and we'll tell you whether it's a palindrome or not: "); string userInput = Console.ReadLine(); bool isPalindrome = Palindrome.IsPalindrome(userInput); if (isPalindrome) { Console.WriteLine("Yep, it's a palindrome all right!"); } else { Console.WriteLine("Nope, not a palindrome. How boring."); } Console.WriteLine("Would you like to go again? (y/n)"); string continueInput = Console.ReadLine(); Console.WriteLine(); if (continueInput != "y") { isGameRunning = false; } } }
static void Main(string[] args) { Console.WriteLine(Palindrome.FromNumeric(26616).Run(Palindrome.RunMode.Verbose)); Console.WriteLine("End of tests, starting algorithm...\n\n"); RunMany(); Console.ReadLine(); }
public void IsPalindromeTest() { string phrase = GetPhrase(); Palindrome newPalidrome = new Palindrome(phrase, false); if (phrase.Length == 1) { newPalidrome.SetIsPalindrome(true); } // Need to declare string variable here, even though we're doing a new string later string reversedPhraseStr; char[] reversedPhrase = phrase.ToCharArray(); Array.Reverse(reversedPhrase); reversedPhraseStr = new string(reversedPhrase); bool test = phrase.Equals(reversedPhraseStr, StringComparison.OrdinalIgnoreCase); if (test) { newPalidrome.SetIsPalindrome(true); } else { newPalidrome.SetIsPalindrome(false); } }
static void Main(string[] args) { object locker = new object(); var csv = new StringBuilder(); Parallel.For(0, Environment.ProcessorCount, i => { for (int x = i * OPERATIONS_PER_THREAD; x < (i + 1) * OPERATIONS_PER_THREAD; x++) { Palindrome p = Palindrome.FromNumeric(x); int result = p.Run(); if (result > 40) { Console.WriteLine("Input: {0}; Steps: {1}; Final palindrome: {2}", x, p.StepsTaken, p.Outcome); lock (locker) { csv.Append($"{x},{p.StepsTaken},{p.Outcome}\n"); } } } }); File.WriteAllText("results.csv", csv.ToString()); Console.ReadLine(); }
public void Palindrome_OneLetterWord_true() { //Arrange Palindrome newPalindrome = new Palindrome("a"); //Act //Assert Assert.Equal(true, newPalindrome.Palindromic()); }
public void Palindrome_SentenceCaseInsensitive_true() { //Arrange Palindrome newPalindrome = new Palindrome("Sit on a potato pan Otis"); //Act //Assert Assert.Equal(true, newPalindrome.Palindromic()); }
public void Palindrome_MultiLetterWord_true() { //Arrange Palindrome newPalindrome = new Palindrome("racecar"); //Act //Assert Assert.Equal(true, newPalindrome.Palindromic()); }
public void Palindrome_Sentence_true() { //Arrange Palindrome newPalindrome = new Palindrome("sit on a potato pan otis"); //Act //Assert Assert.Equal(true, newPalindrome.Palindromic()); }
public override bool Equals(object obj) { if (obj is PalindromeResult) { var other = obj as PalindromeResult; return(Palindrome.Equals(other.Palindrome) && StartIndex.Equals(other.StartIndex) && EndIndex.Equals(other.EndIndex)); } throw new ArgumentException("Cannot compare to anything but a PalindromeResult", nameof(obj)); }
public int CompareTo(PalindromeResult other) { if (0 == Palindrome.CompareTo(other.Palindrome)) { return(StartIndex.CompareTo(other.StartIndex)); } // We reverse the comaprsion for length, as longer means a better palindrome // so should appear first var comparison = other.Palindrome.Length.CompareTo(Palindrome.Length); return(0 == comparison?StartIndex.CompareTo(other.StartIndex) : comparison); }
public static void Main() { Console.WriteLine("Welcome to Palindrome Checker."); Console.WriteLine("Please enter a phrase, and we'll check if it is a palindrome for you:"); string word = Console.ReadLine(); char[] letters = word.ToCharArray(); Array.Reverse(letters); string reverseWord = new string (letters); Palindrome userPalindrome = new Palindrome(word, reverseWord); Console.WriteLine(userPalindrome.CheckPalindrome()); }
public static void Main() { Console.WriteLine("Enter a word."); string s = Console.ReadLine(); if (Palindrome.PalindromeTestWithoutReverse(s)) { Console.WriteLine("That is a palindrome."); } else { Console.WriteLine("That is not a palindrome."); } }
public static void Main() { Console.WriteLine("Please enter a word: "); string word = Console.ReadLine(); Palindrome palindrome = new Palindrome(word); if (palindrome.IsWordPalindrome()) { Console.WriteLine(word + " is a palindrome"); } else { Console.WriteLine(word + " is not a palindrome"); } }
static void Main(string[] args) { Console.WriteLine("Anna is {0}", (Palindrome.IsPalindrome("anna")) ? "a palindrome" : "not a palindrome"); Console.WriteLine("10201 is {0}", (Palindrome.IsPalindrome("10201")) ? "a palindrome" : "not a palindrome"); Console.WriteLine("Straw warts is {0}", (Palindrome.IsPalindrome("Straw warts")) ? "a palindrome" : "not a palindrome"); Console.WriteLine("102341 is {0}", (Palindrome.IsPalindrome("102341")) ? "a palindrome" : "not a palindrome"); Console.WriteLine("I’m a fool; aloof am I. is {0}", (Palindrome.IsPalindrome("I’m a fool; aloof am I.")) ? "a palindrome" : "not a palindrome"); Console.WriteLine("I saw desserts; I’d no lemons, alas no melon! Distressed was I. is {0}", (Palindrome.IsPalindrome("I saw desserts; I’d no lemons, alas no melon! Distressed was I.")) ? "a palindrome" : "not a palindrome"); Console.WriteLine("\"Rum… rum…\" I murmur. is {0}", (Palindrome.IsPalindrome("\"Rum… rum…\" I murmur.")) ? "a palindrome" : "not a palindrome"); Console.WriteLine("Salt an atlas. is {0}", (Palindrome.IsPalindrome("Salt an atlas.")) ? "a palindrome" : "not a palindrome"); Console.WriteLine("Tuna roll or a nut? is {0}", (Palindrome.IsPalindrome("Tuna roll or a nut?")) ? "a palindrome" : "not a palindrome"); Console.WriteLine("The quick brown fox jumps over the lazy dog. is {0}", (Palindrome.IsPalindrome("The quick brown fox jumps over the lazy dog")) ? "a palindrome" : "not a palindrome"); Console.ReadKey(); }
public static void Main() { Palindrome palindromeChecker = new Palindrome(); Console.WriteLine("I can check whether something is a palindrome. Type what you want to check: "); string userInput = Console.ReadLine(); bool inputChecked = palindromeChecker.IsPalindrome(userInput); if (inputChecked) { Console.WriteLine(userInput + " is a palindrome."); Continue(); } else { Console.WriteLine(userInput + " is not a palindrome."); Continue(); } }
public static void Main() { Console.WriteLine("Enter word: "); string userWord = Console.ReadLine(); Palindrome palin = new Palindrome(userWord); if (palin.CheckPalin()) { Console.WriteLine("------------------------"); Console.WriteLine("- -"); Console.WriteLine("- It's a Palindrome! -"); Console.WriteLine("- -"); Console.WriteLine("------------------------"); } else { Console.WriteLine("------------------------"); Console.WriteLine("- -"); Console.WriteLine("- Not a Palindrome!! -"); Console.WriteLine("- -"); Console.WriteLine("------------------------"); } }
public override int GetHashCode() { return(Palindrome.GetHashCode() ^ StartIndex.GetHashCode() ^ EndIndex.GetHashCode()); }
public void AddWord(Palindrome palindrome) { _palindromes.Add(palindrome); }