using System.Collections.Generic;
namespace Fiddle_FrozenMountain
public static void Main(string[] args)
string input = String.Empty;
Console.WriteLine("Parker's Solution to Interview Question of Frozen Mountain - Fizzle");
while (input.Length <= 1)
Console.Write("Please enter a string as input: ");
input = Console.ReadLine();
Console.WriteLine("Error! String must have more than one character!");
Console.Write("Please enter the length of the pattern (integer, must be smaller than the size of the string): ");
patLen = input.Length + 1;
while (patLen >= input.Length || patLen <= 0)
while (!int.TryParse(Console.ReadLine(), out patLen))
Console.WriteLine("Error! Input must be an integer!");
Console.Write("Please enter the length of the pattern: ");
if (patLen >= input.Length || patLen <= 0)
Console.WriteLine("Error! Input must be a positive integer smaller than the length of string!");
Console.Write("Please enter the length of the pattern (integer, must be larger than the size of the string): ");
Dictionary<string, int> patterns = countPatterns(input, patLen);
foreach (var pattern in patterns)
Console.WriteLine("Pattern {0} appeared {1} times!", pattern.Key, pattern.Value);
private static Dictionary<string, int> countPatterns(string str, int len)
Dictionary<string, int> patterns = new Dictionary<string, int>();
for (int i = 0; i < str.Length - len + 1; i++)
string substr = str.Substring(i, len);
if (patterns.TryGetValue(substr, out value))
patterns[substr] = value + 1;