/// <summary> /// Execution function for Day 15 /// </summary> public void Execute15() { UserActionAsync(() => { WriteToConsole("Start execution of Day15"); var parser = GetInputParser("Day15Input.txt"); var originalCode = parser.GetIntCode(); var code = originalCode.ToList(); var droid = new RepairDroid(code); droid.Explore(); var route = droid.GetShortestRoute(new IntVector(0, 0), droid.OxygenSystem); var map = droid.GetRouteMap(route); RunInUiThread(() => { var dialog = new ImageDisplay(map); dialog.Show(); }); WriteToConsole($"The droid needed {route.Count - 1} movement commands to locate the oxygen system"); var time = droid.GetOxygenSpreadingTime(droid.OxygenSystem); WriteToConsole($"It takes {time} minutes until the area is filled with oxygen"); }); }
/// <summary> /// Execution function for Day 13 /// </summary> public void Execute13() { UserActionAsync(() => { WriteToConsole("Start execution of Day13"); var parser = GetInputParser("Day13Input.txt"); var originalCode = parser.GetIntCode(); var code = originalCode.ToList(); var game = new ArcadeGame(code); game.Start(); var blocks = game.Tiles.Where(t => t.Id == TileId.Block).Count(); var view = game.GetGameView(); RunInUiThread(() => { var dialog = new ImageDisplay(view); dialog.Show(); }); WriteToConsole($"The number of blocks in the game is {blocks}"); game = new ArcadeGame(code); game.PlayFree(); WriteToConsole($"The final score is {game.Score}"); }); }
/// <summary> /// Execution function for Day 11 /// </summary> public void Execute11() { UserActionAsync(() => { WriteToConsole("Start execution of Day11"); var parser = GetInputParser("Day11Input.txt"); var originalCode = parser.GetIntCode(); var code = originalCode.ToList(); var hullPaintingRobot = new HullPaintingRobot(code); hullPaintingRobot.Paint(0); WriteToConsole($"The hull paining robot has painted {hullPaintingRobot.PaintedPanels.Count} at least once"); WriteToConsole($"Now we start with a white panel instead of a black one."); hullPaintingRobot = new HullPaintingRobot(code); hullPaintingRobot.Paint(1); var painting = hullPaintingRobot.GetPainting(); RunInUiThread(() => { var dialog = new ImageDisplay(painting); dialog.Show(); }); }); }
/// <summary> /// Execution function for Day 8 /// </summary> public void Execute8() { UserActionAsync(() => { WriteToConsole("Start execution of Day8"); var parser = GetInputParser("Day8Input.txt"); var data = parser.GetInputData(); var encodedImage = data.ToList()[0].ToCharArray().Select(c => int.Parse(c.ToString())).ToList(); var decoder = new SpaceImageFormatDecoder(25, 6, encodedImage); decoder.Decode(); var zeroDigitsPerLayer = decoder.LayeredImage.Select(layer => layer.SelectMany(row => row.Where(d => d == 0)).Count()).ToList(); var fewestZeroDigits = zeroDigitsPerLayer.Min(); var index = zeroDigitsPerLayer.IndexOf(fewestZeroDigits); var targetLayer = decoder.LayeredImage[index]; var ones = targetLayer.SelectMany(row => row.Where(d => d == 1)).Count(); var twos = targetLayer.SelectMany(row => row.Where(d => d == 2)).Count(); var checkSum = ones * twos; WriteToConsole($"The layer with the least amount of zeros is layer {index + 1} and the checksum is {checkSum.ToString("N")}"); AddEmptyLine(); WriteToConsole($"Now we print the decoded image"); AddEmptyLine(); RunInUiThread(() => { var dialog = new ImageDisplay(decoder.DecodedImage); dialog.Show(); }); }); }
/// <summary> /// Execution function for Day 17 /// </summary> public void Execute17() { UserActionAsync(() => { WriteToConsole("Start execution of Day17"); var parser = GetInputParser("Day17Input.txt"); var originalCode = parser.GetIntCode(); var code = originalCode.ToList(); var ascii = new ASCII(code); ascii.Scan(); var checkSum = ascii.GetAlignmentParameters().Sum(); var map = ascii.GetScaffoldMap(); ImageDisplay dialog = null; RunInUiThread(() => { dialog = new ImageDisplay(map); dialog.SetText(ascii.VacuumRobot.X, ascii.VacuumRobot.Y, ascii.VacuumRobotStatus.ToString()); dialog.Show(); }); WriteToConsole($"The sum of the alignment parameters is {checkSum}"); var main = new List <char> { 'C', ',', 'A', ',', 'C', ',', 'A', ',', 'B', ',', 'C', ',', 'A', ',', 'B', ',', 'C', ',', 'B', '\n' }; var a = new List <char> { 'L', ',', '8', ',', 'L', ',', '6', ',', 'L', ',', '9', ',', '1', ',', 'L', ',', '6', '\n' }; var b = new List <char> { 'R', ',', '6', ',', 'L', ',', '8', ',', 'L', ',', '9', ',', '1', ',', 'R', ',', '6', '\n' }; var c = new List <char> { 'R', ',', '6', ',', 'L', ',', '6', ',', 'L', ',', '9', ',', '1', '\n' }; ascii.RobotMoved += (oldP, newP) => { RunInUiThread(() => { dialog.SetText(oldP.X, oldP.Y, string.Empty); dialog.SetColor(oldP.X, oldP.Y, 1); dialog.SetText(newP.X, newP.Y, ascii.VacuumRobotStatus.ToString()); dialog.SetColor(newP.X, newP.Y, 2); }); }; ascii.StartRobot(main, a, b, c, true); WriteToConsole($"The total dust collected is {ascii.DustCollected}"); }); }
private void PictureUpload_Click(object sender, EventArgs e) { var fileContent = string.Empty; var filePath = string.Empty; ImageDisplay.Show(); using (OpenFileDialog openFileDialog = new OpenFileDialog()) { openFileDialog.InitialDirectory = "c:\\"; openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; openFileDialog.FilterIndex = 2; openFileDialog.RestoreDirectory = false; if (openFileDialog.ShowDialog() == DialogResult.OK) { //Get the path of specified file filePath = openFileDialog.FileName; ImageDisplay.Image = new Bitmap(filePath); ImageDisplay.ImageLocation = filePath; ImageDisplay.SizeMode = PictureBoxSizeMode.StretchImage; } } }