Skip to content

Instantly share code, notes, and snippets.

@David-Mimnagh
Created December 13, 2016 10:24
Show Gist options
  • Save David-Mimnagh/9db390eaeb048d6585f79134bce22ad0 to your computer and use it in GitHub Desktop.
Save David-Mimnagh/9db390eaeb048d6585f79134bce22ad0 to your computer and use it in GitHub Desktop.
static void Main(string[] args)
{
string path = "../../input.txt";
String input = File.ReadAllText(path);
int i = 0;
while (i < input.Length)
{
if (input[i] != '(') { i++; continue; }
int length = Convert.ToInt32(input.Substring(i + 1, input.IndexOf('x', i) - i - 1));
int count = Convert.ToInt32(input.Substring(input.IndexOf('x', i) + 1, input.IndexOf(')', i) - input.IndexOf('x', i) - 1));
int clength = 3 + count.ToString().Length + length.ToString().Length;
string part = input.Substring(i + clength, length);
StringBuilder str = new StringBuilder(input);
str.Remove(i, clength);
str.Insert(i, part, count - 1);
input = str.ToString();
i += length * count;
}
Console.WriteLine(input.Length);
Console.Read();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment