Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace RepeatingPrattern
- {
- using System;
- using System.Linq;
- public class GoogleSolutuion
- {
- public static void Main()
- {
- string input = Console.ReadLine();
- var result = FindPattern(input);
- if (result == null)
- {
- result = input;
- }
- Console.WriteLine(result);
- }
- public static string FindPattern(string text)
- {
- if (text == null)
- {
- return null;
- }
- return Enumerable.Range(1, text.Length / 2)
- .Where(n => text.Length % n == 0)
- .Select(n => text.Substring(0, n))
- .Where(pattern => Enumerable.Range(0, text.Length / pattern.Length)
- .SelectMany(i => pattern)
- .SequenceEqual(text))
- .FirstOrDefault();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement