Skip to content

Instantly share code, notes, and snippets.

@David-Mimnagh
Created December 13, 2016 10:24
Show Gist options
  • Save David-Mimnagh/780454a1966ff47803cd53d8d54a098c to your computer and use it in GitHub Desktop.
Save David-Mimnagh/780454a1966ff47803cd53d8d54a098c to your computer and use it in GitHub Desktop.
static void Main(string[] args)
{
string path = "../../input.txt";
String input = File.ReadAllText(path);
Console.WriteLine(getLength(input));
Console.Read();
}
static long getLength(string input)
{
if (!input.Contains('('))
return input.Length;
long fullcount = 0;
int i = 0;
while (i < input.Length)
{
if (input[i] != '(') { i++; fullcount++; 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);
fullcount += getLength(part) * count;
i += clength + length;
}
return fullcount;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment