public static int Run(string input) { var tracker = new bool[1023]; var maxSeat = -1; var lines = InputUtils.SplitLinesIntoStringArray(input); foreach (var line in lines) { if (line.Length == 0) { continue; } var seatNum = GetSeat(line); tracker[seatNum] = true; if (seatNum > maxSeat) { maxSeat = seatNum; } } for (int i = 8; i < 1015; i++) { if (!tracker[i]) { return(i); } } return(-1); }
public static int Run(string input) { var matches = 0; //input = _input; var lines = InputUtils.SplitLinesIntoStringArray(input); _colorDict = GetColorDict(lines); _dynamicColorDict = new Dictionary <string, List <string> >(); foreach (var kvp in _colorDict) { var colors = GetAllContainedColors(kvp.Key, new List <string>()); _dynamicColorDict.Add(kvp.Key, colors); } foreach (var _dynamicColorDictEntry in _dynamicColorDict) { var colors = _dynamicColorDictEntry.Value; if (_dynamicColorDictEntry.Value.Contains("shiny gold")) { Console.WriteLine(_dynamicColorDictEntry.Key); matches++; } } return(matches); }
public static int Run(string input) { var sum = 0; //input = _input; var groups = InputUtils.SplitInputByBlankLines(input); foreach (var group in groups) { var matchedChars = new List <char>(); var lines = InputUtils.SplitLinesIntoStringArray(group); for (int j = 0; j < lines.Length; j++) { var line = lines[j]; if (j == 0) { matchedChars = lines[0].ToCharArray().ToList(); continue; } var stillMatchedChars = new List <char>(matchedChars); for (int i = 0; i < matchedChars.Count; i++) { var matchedChar = matchedChars[i]; if (matchedChar >= 'a' && matchedChar <= 'z' && !line.Contains(matchedChar)) { stillMatchedChars.Remove(matchedChar); } } matchedChars = stillMatchedChars; } sum += matchedChars.Count; } return(sum); }
public static int Run(string input) { var commands = new List <Day8Command>(); //input = _input; var lines = InputUtils.SplitLinesIntoStringArray(input); foreach (var line in lines) { var tokens = line.Trim().Split(" "); var command = new Day8Command() { Command = tokens[0], Value = int.Parse(tokens[1]) }; commands.Add(command); } for (int i = 0; i < commands.Count; i++) { var commandsCopy = commands.ConvertAll(command => new Day8Command() { Command = command.Command, Value = command.Value }); if (commandsCopy[i].Command == "acc") { continue; } else { if (commandsCopy[i].Command == "nop") { commandsCopy[i].Command = "jmp"; } else { commandsCopy[i].Command = "nop"; } } var result = new Day8Program().RunProgram(commandsCopy); if (result != -999999) { return(result); } } return(-1); }
public static long Run(string input) { var map = InputUtils.SplitLinesIntoStringArray(input); var treeValues = new List <int>(); treeValues.Add(GetTreesValue(map, 1, 1)); treeValues.Add(GetTreesValue(map, 3, 1)); treeValues.Add(GetTreesValue(map, 5, 1)); treeValues.Add(GetTreesValue(map, 7, 1)); treeValues.Add(GetTreesValue(map, 1, 2)); long product = 1; foreach (var treeValue in treeValues) { product *= (long)treeValue; } return(product); }
//private static Dictionary<string, List<Day7BagContents>> _dynamicColorDict; public static long Run(string input) { //input = _input2; var lines = InputUtils.SplitLinesIntoStringArray(input); _colorDict = GetColorDict(lines); _dynamicNumBagsDict = new Dictionary <string, long>(); //foreach (var kvp in _colorDict) //{ // var bagCount = GetBagCount(kvp.Key); // if (!_dynamicNumBagsDict.ContainsKey(kvp.Key)) // { // _dynamicNumBagsDict.Add(kvp.Key, bagCount); // } //} return(GetBagCount("shiny gold")); }