Created
December 13, 2016 10:24
-
-
Save David-Mimnagh/9db390eaeb048d6585f79134bce22ad0 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); | |
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