using System; using System.Collections.Generic; using System.IO; using System.Linq; public class Day3 { static void PartA() { // Day 3 ! string path = Directory.GetCurrentDirectory() + "/input.txt"; char[,] map = new char[31, 323]; int trees = 0; using (StreamReader sr = new StreamReader(path)) { for (int y = 0; y < 323; y++) { string line = sr.ReadLine(); for (int x = 0; x < 31; x++) { map[x, y] = line[x]; } } } int _x = 0, _y = 0; while (_y < 323) { if (map[_x, _y] == '#') { trees++; map[_x, _y] = 'X'; } else map[_x, _y] = 'O'; _y++; _x = (_x + 3) % 31; } for (int y = 0; y < 323; y++) { for (int x = 0; x < 31; x++) { Console.Write(map[x, y]); } Console.WriteLine(); } Console.WriteLine(trees); } static void PartB() { // Day 3 ! string path = Directory.GetCurrentDirectory() + "/input.txt"; char[,] map = new char[31, 323]; int trees = 0; using (StreamReader sr = new StreamReader(path)) { for (int y = 0; y < 323; y++) { string line = sr.ReadLine(); for (int x = 0; x < 31; x++) { map[x, y] = line[x]; } } } int _x = 0, _y = 0; long total = 1; Tuple[] slopes = { Tuple.Create(1, 1), Tuple.Create(3, 1), Tuple.Create(5, 1), Tuple.Create(7, 1), Tuple.Create(1, 2), }; foreach (Tuple slope in slopes) { while (_y < 323) { if (map[_x, _y] == '#') { trees++; } _y += slope.Item2; _x = (_x + slope.Item1) % 31; } total *= trees; trees = 0; _x = 0; _y = 0; } Console.WriteLine(total); } }