private async Task <int> Part1() { var test1 = 0; var test2 = 0; var multiplyResult = 0; var is2020 = false; using (AmazonS3Client s3Client = new AmazonS3Client()) { var getInput = new GetInputFromS3(s3Client); dayInput = await getInput.GetDayInput(1); } while (!is2020) { foreach (string dayLine in dayInput) { if (int.TryParse(dayLine, out test1)) { var remander = (2020 - test1).ToString(); is2020 = dayInput.Contains(remander); if (is2020) { test2 = int.Parse(remander); break; } } } } multiplyResult = test1 * test2; return(multiplyResult); }
public async Task <string> RunDay2() { var inputInts = new List <int>(); using (AmazonS3Client s3Client = new AmazonS3Client()) { var getInput = new GetInputFromS3(s3Client); var dayInput = await getInput.GetDayInput(2); var inputString = dayInput.FirstOrDefault(); var inputList = inputString.Split(',').ToList(); inputList.ForEach(x => inputInts.Add(int.Parse(x))); } var p1Noun = 12; var p1Verb = 2; var p1InputArray = new int[inputInts.Count]; inputInts.CopyTo(p1InputArray); var p1InputList = p1InputArray.ToList(); var part1Int = IntercodeProcessing(p1Noun, p1Verb, p1InputList); var p2Noun = 13; var p2Verb = 2; var p2NounInputArray = new int[inputInts.Count]; var p2VerbInputArray = new int[inputInts.Count]; inputInts.CopyTo(p2NounInputArray); var p2NounInputList = p2NounInputArray.ToList(); var part2Int = IntercodeProcessing(p2Noun, p2Verb, p2NounInputList); Console.WriteLine(part2Int); var nounDiff = part2Int - part1Int; var goalOutput = 19690720; var goalDiff = goalOutput - part1Int; var nounIncNeeded = goalDiff / nounDiff; p2Noun = p1Noun + nounIncNeeded; inputInts.CopyTo(p2VerbInputArray); var p2VerbInputList = p2VerbInputArray.ToList(); part2Int = IntercodeProcessing(p2Noun, p2Verb, p2VerbInputList); var verbDiff = goalOutput - part2Int; p2Verb = p1Verb + verbDiff; var p2Result = (p2Noun * 100) + p2Verb; return(string.Format("Part1 Value at 0: {0} || Part2 input result: {1}", part1Int, p2Result)); }
private async Task <string> Part1() { using (AmazonS3Client s3Client = new AmazonS3Client()) { var getInput = new GetInputFromS3(s3Client); dayInput = await getInput.GetDayInput(6); dayInput2 = await getInput.GetDayInput(6); } var answerCollection = ProcessAnswers(dayInput); var answerSum = 0; foreach (var groupAnswer in answerCollection) { answerSum += groupAnswer.Length; } return(String.Format("Part1: {0}", answerSum)); }
private async Task <string> Part1() { using (AmazonS3Client s3Client = new AmazonS3Client()) { var getInput = new GetInputFromS3(s3Client); dayInput = await getInput.GetDayInput(2); } var validPWCount = 0; var part2Count = 0; foreach (string inputRow in dayInput) { var policyAndPW = inputRow.Split(':'); var potentialPW = policyAndPW.Last(); var countAndLetter = policyAndPW.First().Split(' '); var letterCheck = countAndLetter.Last(); var letterChar = letterCheck.FirstOrDefault(); var letterCount = potentialPW.Count(x => x == letterChar); var minAndMax = countAndLetter.First().Split('-'); var min = int.Parse(minAndMax.First()); var max = int.Parse(minAndMax.Last()); if (letterCount >= min) { if (letterCount <= max) { validPWCount++; } } if (potentialPW[min] == letterChar) { if (potentialPW[max] == letterChar) { continue; } else { part2Count++; } } else { if (potentialPW[max] == letterChar) { part2Count++; } } } return(string.Format("Part1: {0}, Part2: {1}", validPWCount, part2Count)); }
private async Task <string> Part1() { using (AmazonS3Client s3Client = new AmazonS3Client()) { var getInput = new GetInputFromS3(s3Client); dayInput = await getInput.GetDayInput(4); } var possiblePasswords = PasswordProcessor(dayInput.First()); return(string.Format("Part 1 potential pass: {0} || Part 2 potential pass: {1}", possiblePasswords[0], possiblePasswords[1])); }
private async Task <int> Part1() { using (AmazonS3Client s3Client = new AmazonS3Client()) { var getInput = new GetInputFromS3(s3Client); dayInput = await getInput.GetDayInput(3); } var treeCount = TreeChecker(3, 1); return(treeCount); }
private async Task <string> Part1() { using (AmazonS3Client s3Client = new AmazonS3Client()) { var getInput = new GetInputFromS3(s3Client); dayInput = await getInput.GetDayInput(12); } var result1 = ProcessDirections(dayInput); var result2 = ProcessDirections2(dayInput); return(string.Format("Part1: {0}, Part2: {1}", result1, result2)); }
private async Task <string> Part1() { using (AmazonS3Client s3Client = new AmazonS3Client()) { var getInput = new GetInputFromS3(s3Client); dayInput = await getInput.GetDayInput(8); } potentialRows = new HashSet <int>(); var accumulation = RetriveAccumulation(dayInput); var part2Result = Part2(potentialRows); return(string.Format("Part1: {0}, {1}", accumulation.Key, part2Result)); }
private async Task <string> Part1() { using (AmazonS3Client s3Client = new AmazonS3Client()) { var getInput = new GetInputFromS3(s3Client); dayInput = await getInput.GetDayInput(9); } var doubleInput = dayInput.Select(x => double.Parse(x)); var errorBit = ProcessXmasEncodeForError(doubleInput.ToList()); var encryptionWeakness = Part2(doubleInput, errorBit); return(string.Format("Part1: {0}, Part2 {1}", errorBit, encryptionWeakness)); }
private async Task <string> Part1() { using (AmazonS3Client s3Client = new AmazonS3Client()) { var getInput = new GetInputFromS3(s3Client); dayInput = await getInput.GetDayInput(7); } var colorDict = new Dictionary <string, string>(); foreach (var inputLine in dayInput) { var lineSplit = inputLine.Split(" contain "); var containSplit = lineSplit[0].Split("bags "); colorDict.Add(containSplit[0], lineSplit[1]); } var colorHold = new HashSet <string>(); foreach (var bagKV in colorDict) { if (bagKV.Value.Contains("shiny gold")) { colorHold.Add(bagKV.Key.Remove(bagKV.Key.Length - 1)); } } for (var i = 0; i < colorHold.Count; i++) { var colorReturn = ProcessColors(colorDict, colorHold.ElementAt(i)); foreach (var colorR in colorReturn) { colorHold.Add(colorR); } } return(string.Format("Part1: {0}, Part2: {1}", colorHold.Count, Part2(colorDict))); }
private async Task <string> Part1() { using (AmazonS3Client s3Client = new AmazonS3Client()) { var getInput = new GetInputFromS3(s3Client); dayInput = await getInput.GetDayInput(10); } var joltages = dayInput.Select(x => int.Parse(x)).ToList(); joltages.Sort(); var oneJoltDiff = 0; var threeJoltDiff = 0; var lastJoltage = 0; foreach (var joltRating in joltages) { var voltDiff = joltRating - lastJoltage; lastJoltage = joltRating; if (voltDiff == 1) { oneJoltDiff++; continue; } if (voltDiff == 3) { threeJoltDiff++; continue; } } var joltResult = oneJoltDiff * (threeJoltDiff + 1); return(string.Format("Part1: {0}", joltResult)); }
private async Task <string> Part1() { using (AmazonS3Client s3Client = new AmazonS3Client()) { var getInput = new GetInputFromS3(s3Client); dayInput = await getInput.GetDayInput(11); } var seatMultiArray = new List <List <char> >(); for (var i = 0; i < dayInput.Count(); i++) { seatMultiArray.Add(dayInput[i].Select(x => x).ToList()); } var settledSeats = ProcessSeatingChart(seatMultiArray); var part1OccupiedCount = OccupiedSeatCount(settledSeats); var part2Seats = ProcessSeatingChart2(seatMultiArray); var part2OccupiedSeats = OccupiedSeatCount(part2Seats); return(string.Format("Part1: {0}, Part2: {1}", part1OccupiedCount, part2OccupiedSeats)); }
private async Task <string> FullDay1() { var part1Result = 0; var part2Running = 0; using (AmazonS3Client s3Client = new AmazonS3Client()) { var getInput = new GetInputFromS3(s3Client); dayInput = await getInput.GetDayInput(1); } foreach (string dayLine in dayInput) { if (int.TryParse(dayLine, out var moduleMass)) { var moduleFuel = FuelCalculator(moduleMass); part1Result += moduleFuel; var additionalWeight = moduleFuel; var additionalFuel = 0; while (additionalWeight > 0) { additionalWeight = FuelCalculator(additionalWeight); additionalFuel += additionalWeight; } part2Running += additionalFuel; } } var part2Result = part1Result + part2Running; var resultString = string.Format("Part 1 Result: {0} || Part 2 Result: {1}", part1Result, part2Result); return(resultString); }
private async Task <string> Part1() { using (AmazonS3Client s3Client = new AmazonS3Client()) { var getInput = new GetInputFromS3(s3Client); dayInput = await getInput.GetDayInput(3); } var matchLocations = new List <(int x, int y, int distance, int steps)>(); var wireADict = WirePath(dayInput[0]); var wireBDict = WirePath(dayInput[1]); var wireALocations = wireADict.Keys.ToList(); var wireBLocations = wireBDict.Keys.ToList(); var intersections = wireALocations.Intersect(wireBLocations); foreach (var intersect in intersections) { if (intersect.Item1 != 0 && intersect.Item2 != 0) { wireADict.TryGetValue(intersect, out var aSteps); wireBDict.TryGetValue(intersect, out var bSteps); var steps = aSteps + bSteps; var dist = Math.Abs(intersect.Item1) + Math.Abs(intersect.Item2); matchLocations.Add((intersect.Item1, intersect.Item2, dist, steps)); } } var minDist = matchLocations.OrderBy(d => d.distance).ToList(); var minSteps = matchLocations.OrderBy(s => s.steps).ToList(); Console.WriteLine("min Dist: {0}", minDist.First().distance); Console.WriteLine("min Steps: {0}", minSteps.First().steps); return(String.Format("min Dist: {0} || min Steps: {1}", minDist.First().distance, minSteps.First().steps)); }
private async Task <List <string> > Part1() { using (AmazonS3Client s3Client = new AmazonS3Client()) { var getInput = new GetInputFromS3(s3Client); dayInput = await getInput.GetDayInput(4); } var validPassports = new List <string>(); var individualPassports = ProcessPassports(dayInput); foreach (var passport in individualPassports) { if (passport.Contains("byr:") && passport.Contains("iyr:") && passport.Contains("eyr:")) { if (passport.Contains("hgt:") && passport.Contains("hcl:") && passport.Contains("ecl:") && passport.Contains("pid")) { validPassports.Add(passport); } } } return(validPassports); }
private async Task <string> Part1() { using (AmazonS3Client s3Client = new AmazonS3Client()) { var getInput = new GetInputFromS3(s3Client); dayInput = await getInput.GetDayInput(5); } var seatIdList = new List <int>(); foreach (var boardingPass in dayInput) { var maxRow = 127; var minRow = 0; var maxColumn = 7; var minColumn = 0; foreach (var passKey in boardingPass) { switch (passKey) { case 'F': maxRow = maxRow - RowCodeConvert(minRow, maxRow); continue; case 'B': minRow = minRow + RowCodeConvert(minRow, maxRow); continue; case 'L': maxColumn = maxColumn - RowCodeConvert(minColumn, maxColumn); continue; case 'R': minColumn = minColumn + RowCodeConvert(minColumn, maxColumn); continue; default: Console.WriteLine("This is an invalid character."); continue; } } var seatId = (maxRow * 8) + maxColumn; seatIdList.Add(seatId); } var minSeatId = seatIdList.Min(); var maxSeatId = seatIdList.Max(); var missingSeat = 0; for (var i = minSeatId; i < maxSeatId; i++) { if (!seatIdList.Contains(i)) { missingSeat = i; break; } } var fullResult = string.Format("Part1: {0}, Part2: {1}", maxSeatId, missingSeat); return(fullResult); }