Created
December 13, 2016 10:24
-
-
Save David-Mimnagh/780454a1966ff47803cd53d8d54a098c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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