public int Part1() { string input = InputUtils.GetDayInputString(16); List <int> inputList = input.ToCharArray().Select(p => int.Parse(p.ToString())).ToList(); List <int> newList = new List <int>(); for (int phase = 0; phase < 100; phase++) { for (int i = 0; i < inputList.Count; i++) { // calculate position i in new list, which is // the sum of all of the previous values int sum = 0; for (int j = 0; j < inputList.Count; j++) { sum += GetMultiplier(i + 1, j) * inputList[j]; } newList.Add(Math.Abs(sum) % 10); } inputList = new List <int>(newList); newList.Clear(); } StringBuilder sb = new StringBuilder(); for (int o = 0; o < 8; o++) { sb.Append(inputList[o]); } return(int.Parse(sb.ToString())); }
public int Part2() { var input = InputUtils.GetDayInputString(2018, 8); List <int> inputInts = input.Split(' ').Select(p => int.Parse(p)).ToList(); Node root = BuildTree(inputInts); int sum = GetNodeValue(root); return(sum); }
public int Part1() { var input = InputUtils.GetDayInputString(2018, 8); List <int> inputInts = input.Split(' ').Select(p => int.Parse(p)).ToList(); Node root = BuildTree(inputInts); // add up the sum int sum = GetMetadataSum(root); return(sum); }
public int Part2() { string input = InputUtils.GetDayInputString(16); int offset = 5970417; List <int> oo = input.ToCharArray().Select(p => int.Parse(p.ToString())).ToList(); List <int> originalInput = new List <int>(); for (int c = 0; c < 10000; c++) { originalInput.AddRange(oo); } for (int phase = 0; phase < 100; phase++) { int sum = 0; // we only need to check the tail, and they are all 1s in // the repeating pattern at that point // from the end, we take each digit going backwards // and use it as part of the sum for the next digit, // because the repeating pattern makes for zeroes all the // way up to the point we are calculating for (int i = 1; i < originalInput.Count - offset + 1; i++) { sum += originalInput[originalInput.Count - i]; sum = Math.Abs(sum) % 10; // since we're going backwards, just replace the // slot we just used with what we just computed originalInput[originalInput.Count - i] = sum; } } StringBuilder sb = new StringBuilder(); for (int o = 0; o < 8; o++) { sb.Append(originalInput[offset + o]); } return(int.Parse(sb.ToString())); }
public int Part2() { string input = InputUtils.GetDayInputString(2018, 5); var letters = Enumerable.Range((int)'a', 26).Select(p => (char)p).ToList(); int smallest = int.MaxValue; foreach (var letter in letters) { // remove letter string newInput = input.Replace(letter.ToString(), String.Empty); newInput = newInput.Replace(char.ToUpper(letter).ToString(), String.Empty); int collapsed = CollapsePolymer(newInput); if (collapsed < smallest) { smallest = collapsed; } } return(smallest); }
public int Part1() { string input = InputUtils.GetDayInputString(2018, 5); return(CollapsePolymer(input)); }