static void Main() { Console.WriteLine("What is the minimum amount of characters we need to append/prepend to make a string a palindrome?\n"); Console.WriteLine("Let's find out!\n"); Console.Write("Enter a single string containing no spaces: "); // we will assume the user doesn't care about case sensitivity for this example string word = Console.ReadLine().ToLower(); //TODO: validation & reprompt if invalid, add option for case sensitivity option from user input int resultPrepend = Palindromes.MinCharsRequiredForPalindrome(word); int resultAppend = Palindromes.MinCharsRequiredForPalindrome(Palindromes.ReverseString(word)); int requiredCharacters = (resultPrepend < resultAppend) ? resultPrepend : resultAppend; if (requiredCharacters == 0) { Console.WriteLine("No characters are needed because the entered word is already palindrome!"); } else { Console.WriteLine("We need to prepend/append {0} characters for '{1}' to become a palindrome.", requiredCharacters, word); } //TODO: we could extend the granularity further, and tell the user how many characters, if we prepend or append, the string // that is added to the original string, and the final palindrome }
public static void Main() { Console.WriteLine("Please enter a word to check if it's a palindrome:"); string userInput = Console.ReadLine(); Palindromes.Method(userInput); }
static void Main(string[] args) { // 1. SORTED ARRAY SMALLEST TO HIGHEST int[] nums = new int[] { 9, 12, 4, 7, 8, 11 }; var a = new SortArray(); var ar = a.SortedArrayByLowestNumber(nums); foreach (var i in ar) { Console.WriteLine(i); } // 2. FIBONNACI CALCULATE NTH SEQUENCE var f = Fibonacci.CalculateNthFibonacci(13); Console.WriteLine(f); // 3. PALINDROME var p = new Palindromes(); var ps = p.IsPalindromes("A man a plan a canal Panama"); Console.WriteLine(ps); // 4. SQUARE ROOT var r = new SquareRoot(); var sq = r.SquareRootNumber(60); Console.WriteLine(sq); }
public void ShouldSucceed() { Palindromes.GetReversed(0, 2).Should().Be(0); Palindromes.GetReversed(0b101, 2).Should().Be(0b101); Palindromes.GetReversed(0b1101, 2).Should().Be(0b1011); Palindromes.GetReversed(0b100111010, 2).Should().Be(0b10111001); }
public void ShouldSucceed() { Palindromes.GetReversed(0).Should().Be(0); Palindromes.GetReversed(7).Should().Be(7); Palindromes.GetReversed(13).Should().Be(31); Palindromes.GetReversed(314).Should().Be(413); }
public string Solve(SingleLimitProblemArgs arguments) { long maxFactor = (long)Math.Pow(10, arguments.Limit) - 1; long minFactor = (long)Math.Pow(10, arguments.Limit - 1); long maxPalindrome = 0; for (long f1 = maxFactor; f1 >= minFactor; f1--) { if (f1 * maxFactor < maxPalindrome) { break; } for (long f2 = maxFactor; f2 >= minFactor; f2--) { long result = f1 * f2; if (result > maxPalindrome && Palindromes.IsPalindromic(result, 10)) { maxPalindrome = result; } if (result <= maxPalindrome) { break; } } } return(maxPalindrome.ToString()); }
public void PalindromeReturnFalse() { var p = new Palindromes(); var pw = p.IsPalindromes("laptop"); Assert.False(pw); }
public void PalindromeReturnTrue() { var p = new Palindromes(); var pw = p.IsPalindromes("A man a plan a canal Panama"); Assert.True(pw); }
public object GetResult() { const int max = 1000000; return(Enumerable.Range(0, max) .Where(x => Palindromes.IsPalindrome(x, 2) && Palindromes.IsPalindrome(x)) .Sum()); }
public void TestFindInsertions() { Assert.Equal(1, Palindromes.FindInsertions("ab")); Assert.Equal(0, Palindromes.FindInsertions("aa")); Assert.Equal(3, Palindromes.FindInsertions("abcd")); Assert.Equal(2, Palindromes.FindInsertions("abcda")); Assert.Equal(4, Palindromes.FindInsertions("abcde")); }
public void PalindromeTest() { BigInteger b; b = 123321; Assert.IsTrue(Palindromes.IsPalindrome("asdffdsa")); Assert.IsTrue(Palindromes.IsPalindrome(432234)); Assert.IsTrue(Palindromes.IsPalindrome(4342434)); Assert.IsTrue(Palindromes.IsPalindrome(b)); }
public void ShouldSucceed() { Palindromes.IsPalindrome(0).Should().BeTrue(); Palindromes.IsPalindrome(7).Should().BeTrue(); Palindromes.IsPalindrome(13).Should().BeFalse(); Palindromes.IsPalindrome(33).Should().BeTrue(); Palindromes.IsPalindrome(777).Should().BeTrue(); Palindromes.IsPalindrome(70707).Should().BeTrue(); Palindromes.IsPalindrome(70737).Should().BeFalse(); }
public void ShouldSucceed() { Palindromes.IsPalindrome(0, 2).Should().BeTrue(); Palindromes.IsPalindrome(0b101, 2).Should().BeTrue(); Palindromes.IsPalindrome(0b1101, 2).Should().BeFalse(); Palindromes.IsPalindrome(0b110011, 2).Should().BeTrue(); Palindromes.IsPalindrome(0b1010101, 2).Should().BeTrue(); Palindromes.IsPalindrome(0b1111111, 2).Should().BeTrue(); Palindromes.IsPalindrome(0b1111011, 2).Should().BeFalse(); }
public void Palindromes_Constructor_Result() { // Arrange string userInput = "Hello"; // Act Palindromes newPalindromes = new Palindromes(userInput); // Assert Assert.Equal(userInput, newPalindromes.GetUserString()); }
public HomeModule() { Get["/"] = _ => { return(View["index.cshtml"]); }; Post["/"] = _ => { Palindromes newPalindromes = new Palindromes(Request.Form["word"]); newPalindromes.SetReverseString(); return(View["index.cshtml", newPalindromes]); }; }
public void LychrelTest() { Assert.AreEqual(1, Palindromes.LychrelValue(56)); Assert.AreEqual(2, Palindromes.LychrelValue(57)); Assert.AreEqual(3, Palindromes.LychrelValue(59)); Assert.AreEqual(24, Palindromes.LychrelValue(89)); Assert.AreEqual(55, Palindromes.LychrelValue(10911)); Assert.AreEqual(-1, Palindromes.LychrelValue(196)); BigInteger b = BigInteger.Parse("1186060307891929990"); Assert.AreEqual(261, Palindromes.CalculateLychrel(b, 280)); }
public void SetReverseString_Reversal_InputBackwards() { // Arrange string userInput = "Hello"; string reverseInput = "olleH"; Palindromes newPalindromes = new Palindromes(userInput); // Act newPalindromes.SetReverseString(); // Assert Assert.Equal(reverseInput, newPalindromes.GetReverseString()); }
static void Main(string[] args) { int [] Ex1 = { 1232, 121, 96235, 72627, 801108, 523925, 9, 865568 }; string [] Ex2 = { "a", "ama", "ralar", "aprovado", "rodador", "reter", "aprenda", "selecionado", "mussum" }; int [] Ex3 = { 4, 7, 17, 9, 79, 95, 4, 66, 36, 17, 70, 51, 24, 35, 65, 64, 60, 19, 27, 1 }; string [] Ex4 = { "V", "Q", "P", "U", "S", "E", "B", "I", "J", "C", "N", "Z", "X", "T", "F", "A", "K", "W", "L", "Y" }; Palindromes p = new Palindromes(); p.getPalindromes(Ex1); Console.WriteLine("\n"); p.getPalindromes(Ex2); }
public static void Main() { Console.WriteLine("Please enter a word"); string input = Console.ReadLine(); Palindromes userPalindromes = new Palindromes(input); if (userPalindromes.IsItPalindromes()) { Console.WriteLine("It is a Palindromes!"); } else { Console.WriteLine("It is not a Palindromes!"); } }
public void CompareStrings_Compare_True() { // Arrange string userInput = "1001"; string reverseInput = "olleH"; Palindromes newPalindromes = new Palindromes(userInput); newPalindromes.SetReverseString(); // Act newPalindromes.CompareStrings(); // Assert Assert.Equal(true, newPalindromes.CompareStrings()); }
static void Main(string[] args) { try { if (args.Length == 0) { throw new ArgumentException("Input string required"); } string input = args[0], result = ""; if (Palindromes.isPalindromeOrAnagramOfPalindrome(input)) { int halfLength = (int)Math.Ceiling(input.Length / 2f); bool isSymmetric = true; for (int i = 0; i < halfLength; i++) { int revI = input.Length - 1 - i; if (input.ElementAt(i) != input.ElementAt(revI)) { isSymmetric = false; break; } } result = isSymmetric ? "is a palindrome" : "is a anagram of a palindrome"; } else { result = "is neither a palindrome, nor an anagram of a palindrome"; } Console.WriteLine("Input string '{0}' {1}", input, result); } catch (ArgumentException exception) { Console.WriteLine("EXCEPTION: Invalid program argument. {0}", exception.Message); } catch (Exception exception) { Console.WriteLine("EXCEPTION: Program error. {0}", exception.Message); } }
public object GetResult() { int max = 0; for (int left = 100; left <= 999; left++) { for (int right = left; right <= 999; right++) { int product = left * right; if (product > max && Palindromes.IsPalindrome(product)) { max = product; } } } return(max); }
public void ReverseTest() { BigInteger b, b2; Assert.AreEqual(1, Palindromes.Reverse(1)); Assert.AreEqual(9, Palindromes.Reverse(9)); Assert.AreEqual(0, Palindromes.Reverse(0)); Assert.AreEqual(11, Palindromes.Reverse(11)); Assert.AreEqual(13, Palindromes.Reverse(31)); Assert.AreEqual(432113, Palindromes.Reverse(311234)); b = 1234; b2 = 4321; Assert.AreEqual(b2, Palindromes.Reverse(b)); b = 0; Assert.AreEqual(b, Palindromes.Reverse(b)); Assert.AreEqual("asdfasdf", Palindromes.Reverse("fdsafdsa")); }
public void IsAdvancedPalindrome(string text, bool isPalindrome) { Palindromes.IsPalindrome(text).Should().Be(isPalindrome); }
public void IsPalindrome_ShouldReturnTrueOrFalse_IfWordIsPalindrome(string str, bool expectedValue) { var result = Palindromes.IsPalindrome(str); Assert.Equal(result, expectedValue); }
public bool isPalindrome(string s) { return(Palindromes.isPalindrome(s)); }
public void ShouldThrow() { Func <bool> f = () => Palindromes.IsPalindrome(-1); f.Should().Throw <ArgumentOutOfRangeException>(); }
public void ShouldThrow() { Func <int> f = () => Palindromes.GetReversed(-1); f.Should().Throw <ArgumentOutOfRangeException>(); }
public void IsPalindrome_UserInputIsString_True() { Palindromes testPalindromes = new Palindromes(); Assert.AreEqual(true, testPalindromes.IsPalindrome("racecar")); }
public void IsPalindromic_ShouldBeTrueForPalindromesOnly(long number, byte @base, bool expectedValue) { bool value = Palindromes.IsPalindromic(number, @base); Assert.AreEqual(expectedValue, value); }