public bool isSuperSpecialValidPassword(int pw) { int[] pwDigits = SantasLittleHelperClass.IntToDigitArray(pw); int nr = pwDigits[0]; int end = pwDigits.Length - 1; if (nr == pwDigits[1] && nr != pwDigits[2]) { return(true); } nr = pwDigits[end]; if (nr == pwDigits[end - 1] && nr != pwDigits[end - 2]) { return(true); } for (int i = 1; i < end - 1; i++) { int current = pwDigits[i]; int before = pwDigits[i - 1];; int next = pwDigits[i + 1];; int afterNext = pwDigits[i + 2];; if (current == next && current != before && current != afterNext) { return(true); } } return(false); }
private List <Point> handleInstruction(string[] instructions) { int x = 0; int y = 0; List <Point> result = new List <Point>(); foreach (string instruction in instructions) { char c = instruction[0]; int steps = SantasLittleHelperClass.StringToInt(instruction.Substring(1)); int step = (c == 'D') || (c == 'L') ? -1 : 1; int goal = 0; if (c == 'U') { goal = y + steps; while (y < goal) { y += step; result.Add(new Point(x, y)); } } else if (c == 'D') { goal = y - steps; while (y > goal) { y += step; result.Add(new Point(x, y)); } } else if (c == 'R') { goal = x + steps; while (x < goal) { x += step; result.Add(new Point(x, y)); } } else if (c == 'L') { goal = x - steps; while (x > goal) { x += step; result.Add(new Point(x, y)); } } } return(result); }
private int[] readImageDataFromInputfile() { string[] fileLines = SantasLittleHelperClass.TextfileToStringArray(INPUT_FILE_PATH); string input = fileLines[0]; List <int> numbers = new List <int>(); foreach (char c in input) { numbers.Add(int.Parse(c.ToString())); } return(numbers.ToArray()); }
private void loadDirectionsFromFile() { string[] input = SantasLittleHelperClass.TextfileToStringArray(INPUT_FILE_PATH); List <string> directions = new List <string>(); for (int i = 0; i < input.Length; i++) { directions.Add(input[i]); } wire1_dirs = directions.ToArray()[0].Split(','); wire2_dirs = directions.ToArray()[1].Split(','); }
public Day2() { string[] fileLines = SantasLittleHelperClass.TextfileToStringArray(INPUT_FILE_PATH); List <int> program = new List <int>(); for (int i = 0; i < fileLines.Length; i++) { string[] split = fileLines[i].Split(','); for (int j = 0; j < split.Length; j++) { program.Add(SantasLittleHelperClass.StringToInt(split[j])); } } originalMemory = program.ToArray(); }
private int[] inputFileToIntArray() { string[] fileLines = SantasLittleHelperClass.TextfileToStringArray(InputFilePath); List <int> program = new List <int>(); for (int i = 0; i < fileLines.Length; i++) { string[] split = fileLines[i].Split(','); for (int j = 0; j < split.Length; j++) { program.Add(SantasLittleHelperClass.StringToInt(split[j])); } } return(program.ToArray()); }
public int calcTotalFuelRequirement() { string[] fileLines = SantasLittleHelperClass.TextfileToStringArray(INPUT_FILE_PATH); int[] masses = new int[fileLines.Length]; for (int i = 0; i < fileLines.Length; i++) { masses[i] = SantasLittleHelperClass.StringToInt(fileLines[i]); } int totalFuelReq = 0; for (int i = 0; i < masses.Length; i++) { totalFuelReq += calcFuel(masses[i]); } return(totalFuelReq); }
public Day4() { var minAndMaxVal = input.Split('-'); if (minAndMaxVal.Length != 2) { throw new ArgumentException("wrong kind of input string, must be two numbers seperated by a '-'"); } min = SantasLittleHelperClass.StringToInt(minAndMaxVal[0]); max = SantasLittleHelperClass.StringToInt(minAndMaxVal[1]); if (min > max) { throw new ArgumentException("wrong kind of input string, first number must be smaller than the second"); } }
private void ParseOpCodeValue(int opCodeValue, out OpCode opCode, out ParameterMode[] paramModes) { int[] digits = SantasLittleHelperClass.IntToDigitArray(opCodeValue); opCode = (OpCode)(opCodeValue % 100); if (!Enum.IsDefined(typeof(OpCode), opCode)) { throw new ArgumentException(); } List <ParameterMode> modes = new List <ParameterMode>(); for (int i = digits.Length - 3; i >= 0; i--) { modes.Add((ParameterMode)digits[i]); } while (modes.Count < 3) { modes.Add(ParameterMode.Position); } paramModes = modes.ToArray(); }
public bool isValidPassword(int pw) { int[] pwDigits = SantasLittleHelperClass.IntToDigitArray(pw); // It is a six-digit number. if (pwDigits.Length != 6) { return(false); } //Two adjacent digits are the same (like 22 in 122345). if (!areThereAdjacentDigits(pwDigits)) { return(false); } //Going from left to right, the digits never decrease; they only ever increase or stay the same (like 111123 or 135679). if (!doDigitsIncrease(pwDigits)) { return(false); } return(true); }
private string[] getCommandsFromFile() { return(SantasLittleHelperClass.TextfileToStringArray(INPUT_FILE_PATH)); }
private Dictionary <Point, int> instructionsToWireDictionary(string[] instructions) { Dictionary <Point, int> result = new Dictionary <Point, int>(); int wire_length = 0; int x = 0; int y = 0; foreach (string instruction in instructions) { char c = instruction[0]; int steps = SantasLittleHelperClass.StringToInt(instruction.Substring(1)); int step = (c == 'D') || (c == 'L') ? -1 : 1; int goal = 0; if (c == 'U') { goal = y + steps; while (y < goal) { y += step; wire_length++; try { result.Add(new Point(x, y), wire_length); } catch (Exception e) { } } } else if (c == 'D') { goal = y - steps; while (y > goal) { y += step; wire_length++; try { result.Add(new Point(x, y), wire_length); } catch (Exception e) { } } } else if (c == 'R') { goal = x + steps; while (x < goal) { x += step; wire_length++; try { result.Add(new Point(x, y), wire_length); } catch (Exception e) { } } } else if (c == 'L') { goal = x - steps; while (x > goal) { x += step; wire_length++; try { result.Add(new Point(x, y), wire_length); } catch (Exception e) { } } } } return(result); }