public static void Main()
Console.WriteLine("(1)\t====== Remove Extra Chars ======" + "\n\n\t\tReturn a string where the number of consecutive characters of the same value is limited to the parameter supplied\n");
Console.WriteLine("aaabbcccccdddde".RemoveConsecutiveChars(2));
Console.WriteLine("\n\n(2)\t====== Fizz Buzz ======" + "\n\n\t\tShould return each number between zero and its parameter (inclusive) but replaces multiples of 3 with 'Fiz' and multiples of 5 with 'Buz'" + "\n\n\t\tWhere the number of 'z' characters each word is the same as the other factor of the input number" + "\n\n\t\tFor multiples of both 3 and 5 replace the number with both of the corresponding 'Fizz'-'Buzz' words. eg 15=\"Fizzzzz-Buzzz\"\n");
foreach (var s in FizzBuzz(100))
public static void TestRemoveConsecutiveChars()
var expectedResult = "aabbccdde";
var result = "aaabbcccccdddde".RemoveConsecutiveChars(2);
Console.Write(expectedResult == result ? " equals " : " does not equal ");
Console.Write(expectedResult);
public static void TestFizzBuzz()
var expectedResult = "Fizzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz-Buzzzzzzzzzzzzzzzzzzzz";
var result = FizzBuzz(100);
Console.Write(expectedResult == result ? " equals " : " does not equal ");
Console.Write(expectedResult);
public static string FizzBuzz(int input)
var numberOfThrees = input / 3;
var numberOfFives = input / 5;
string result = string.Empty;
var stringBuilder = new StringBuilder();
for (var i = 0; i < numberOfThrees; i++)
stringBuilder.Append("z");
result += stringBuilder.ToString();
if (numberOfThrees > 0 && numberOfFives > 0)
var stringBuilder = new StringBuilder();
for (var i = 0; i < numberOfFives; i++)
stringBuilder.Append("z");
result += stringBuilder.ToString();
public static class StringExtensions
public static string RemoveConsecutiveChars(this String input, int consecutiveMax)
var result = string.Empty;
var stringBuilder = new StringBuilder();
var currentConsecutiveChar = ' ';
var currentConsecutiveLength = 0;
for (var i = 0; i < input.Length; i++)
var currentChar = input[i];
if (currentConsecutiveChar == currentChar)
currentConsecutiveLength++;
currentConsecutiveLength = 0;
currentConsecutiveChar = currentChar;
if (currentConsecutiveLength < consecutiveMax)
stringBuilder.Append(input[i]);
result = stringBuilder.ToString();