Skip to content

Instantly share code, notes, and snippets.

@lennartb-
Created December 3, 2020 11:11
Show Gist options
  • Save lennartb-/b42cc5a437fae951482de9e462d5ccf0 to your computer and use it in GitHub Desktop.
Save lennartb-/b42cc5a437fae951482de9e462d5ccf0 to your computer and use it in GitHub Desktop.
Advent Of Code 2020 - Day 3
..#..#......###.#...#......#..#
...#.....#...#...#..........#..
....#.#...............#.#.#....
.........#.......##............
#.#....#.#####.##.#........#..#
.....#...##.#..#.##...#.#..#...
#.#..###.#........#....##...#.#
..###.....#..###.....##........
#.#.#...........#.....#.#....##
...#.#.##.##.#.#......#...##.#.
.....##.#..#....#..#...##...###
...#.....#..#..#...#.#....##...
.#...##.#.........#...#.#......
....#...#.....#......#...#.....
.#...#.....#....#......#...#...
#...#......####..##...###......
....#..#......##.##.....#..#...
....#....#.......#..#...#....#.
...##..#.##..#.#...#..##.......
##.#..#.....#.##.#....#..##....
#....#....#.....#..#.#.#.....#.
##...#.###.....#....#..#.#.#...
#..#.......#...#.#...#.#.....#.
....#.#.......#.....###..#..#.#
......####...#.#..#..#.#.#.#...
#...##.....#...#.#.........#.#.
......#...##.#..#.#........#...
..#.#...........#..##...###.##.
#......#.#......#.....#.....#.#
.#...............###.#.###.....
...#...........##..#...##..##.#
#......#.##.#............#.##.#
.#.#....#....###........#..#...
...##.#.#..#.##.#..##..#.##..##
.....#...#.#.#...#....#......#.
..............#...##...........
..............##........#..###.
.#.##.......#.....##.#......#..
..#......#..#.#####..#.#.......
#.#..#...#.#..#....#..#.##..#..
...##.......#.#............#...
...#....#..#.##.###.......#.###
..###..#....#..#.....##...#..#.
..#.###.##......###....#....##.
...#...##...###....##.....###.#
.....#.....#.#.#.........#..###
#.#......#.#..#.####..#........
#....#.##.......##.............
..##...........#....#.....##..#
..#...#...........#....#...#...
...#...#...#.....#..#....#....#
#......##.........#.#...##...#.
.##..#...#.....#....#.##.####.#
#..##.##.#......#.............#
.#.....#..##.###.#.#.#.........
.###....###..#....#..#.#.#..##.
....#........#..#....##..#.#.#.
.....#..........#..........#...
.#.##..#..#...#..#.##.#.##.....
.#....#...#......#.#..##.##..#.
.###.#...#.#.##....#.....#..##.
......##.......#..#.......#.#.#
.##.#.#.#......#.......#.......
#..#...##......#.......#......#
...#..#...##.#...#..##.........
.....#..###...##...#..#.#...#.#
..#.#.#....##..#.#.#.#...#.....
.....#.#.#..#..#.#.#...#.......
#.#.#...#.#.....#.#.#.##.###...
.....#.#.....####..#...........
..#.#.#...........##..#.#....#.
.#..#......#..#...........###..
..#...###.##......#..###...#..#
#.#..#.....#..#.##.#..#.#.....#
.....................#.#..#....
...##..##...#.#..#..##.#....#..
.#..#.#....#...#.#.##..........
....##.....#..#..##.........##.
..##...##........#.#....#...###
.#...#............#.#.#.#......
#...#........#..#..#...#.#.....
..#..........#.......###.##....
#...........###..#....##..#.##.
##...#..#.##.....#...........#.
.#..##.....#..#.#.....##.#..#.#
..#..#.##....#.........#.#.#...
#..#...#...#..#...........##...
.....#.......#.#......#.#.#...#
..#.#..#..#.#.#.......#.#...#..
......#.....##.....#.....##.##.
#.#..#......#......#.####.##...
.####...#####.#....#.#..##.....
............#....#....#....##..
###.........#............#.#...
...#...#....#.##..#...#......##
...##.#.#.##.##.#.....#...#.#..
...#.....#...#..##......#.#.##.
.##.#......##................##
......#.....#..##.............#
#.#...##..#..#..#.##.....#..#..
#......###.....#....##...##...#
....#..#.....#.......####...##.
#.#...#.#...#..........#..##..#
....#..#....#................##
.####..#........#..#.#...#.....
##.###...#.##........#..##.....
..###..##...#...#..#...##.....#
......#..##....................
.#...#......#.#.##..#........#.
..#...#####.....##.....#...#...
.#..#....#..#....##.#....#..##.
.#.....##..###.#.....#.#.#.##..
#..##.....##...#.....#..#.#....
#.##......#.#......#..........#
#####........#.............#...
.#..#..##..#....#.....#..####..
...#..##.##...####....#.##...##
..........#....#...........##.#
#...##...#...##....#.....#.....
.......#..#.....#.#.#.#.#.....#
...#..##..####..#..##.#.##....#
#...#...#...........#.#.....#.#
..#.....##...###.........#..##.
.......##..#.......#.......##..
#.#....#....#.###............#.
...#......#.#.............#.#..
......#..#....#....#....#..#...
.....##..#...........##...#.##.
..#....#.##.#......#...........
#...#....#.#.#.#.#..#..........
.#..#..........#..#.#.....#....
.....##......##....#.#.....#.#.
.....#..#..........#....#.....#
....#..#..#.#...#.#..#..#..##.#
.#..##.#..##...###.#..........#
..###..#......#...##...#.#.....
..#...#...#.....#.......#....#.
#...##..#.##.#....##.....#.....
..#.#.....#...#...#............
.......#.#.#..#.....###.#...##.
....##.......#####...##..##..#.
#...#.##.....#.#...##.........#
..#.##..........#..###.#....#..
#......#.##...#...#.....###....
................#.##...........
##.###.#.#.#.##......##..#....#
..#.#........##..#..##.........
###....#..#....#..##....#.....#
#......#..#...........#.#...##.
...###.......#...#......##..#.#
.......#...##.#.#...#.##......#
......##..#...##.#.#...##....#.
..#...#...#...#.#.....#..##..#.
..##...#.....#.....#..##.......
....#........#.#.##.......#.#..
#...#..##..#..##..#...#......#.
...#..#.#.#..#..#..####...#....
#..#..#......#......#..#.######
#..#..#..#........#..#.#....###
#..##..#.#.##.....#..#......#.#
##.......##.#..#.............#.
..........#.#..#..#............
....#.#.#.#...#......#......#..
###.#.#.........#.......#...##.
#.............####..#...#.##...
....##.......#................#
###...#..#......##....#.####.#.
..##.##.#.#.#.#...#.......#...#
.....#.##......#.......##..#.#.
.#...#.##..#.......#.#....#.#.#
##...##..#....#..#...#....#....
..........#...##.#..##.......##
#.#...#....#......#.#.......###
......#...#.##....#....##.#.##.
..#..#.......#.......#....##...
##..##.......##............#.#.
.#.#...#..#.#.###......#.......
#...#..##....#...###..#.#.....#
.#.....#........#..##.#.#.#....
..#.##....#..#...........#...#.
.....#.#...#.##..###...#...#...
#....####.......#..#.#...#.....
....#.....#....##..#.##.....###
........#.#.....###....#.#.....
...#.....#.##.....#......#.....
.....#...####......###..#...##.
#.#......#..........#..##.#..#.
..##......###...#...#.......#..
#...#.#...#.#.........#........
....#..#.##.#.##.###..#.....#..
.#.#.#......#.#........#.....#.
.....#.#..#....#...#.....#.#.##
##.............#..#.....#.#....
#............#..#....##......##
#....#......#......#....##..#..
.#....#............#......##..#
..#.#.#..#.#....##.#.......#.##
#.##.....#...#......#...#......
.......#...........#..#.##..#.#
##.....##.#.....####..........#
...#.......#.#.............#..#
...##........##..#..#.#........
.#.##...#.....##.#......#....#.
.#................#.#...#..#...
#....#.#.#......#.#.#.##....#..
..#......#............#...#....
###..#.##........#....##.#...#.
.#..#..#......##...............
....##.............#....##...##
..#.#..#.#####....##.......###.
......#...#..#.#....#.#..#...#.
.........#..##.##...#....##..##
.............#.##....###.#.....
..#................#..#.#..#...
...#........#......#..###......
.#.#.#....#.........#...###.###
.........#..#.#......##.....#..
#...##..#.#.###..###...........
...#.#.#..#......#..##.#.##....
.....##.......#................
.##....#.#.#.##.....#.##......#
...#........#...##.#.##..##...#
..#..........#.#......####..##.
............#.#.#.#.....#......
..##.####.#..#....#..#..##.....
......#........#...#..#.#..###.
#.#..............#..#...#..#...
....#............#...#..#...##.
..##....#...##.##.#..........##
..#..#.........#..#.....#.#....
#.....#.###...##...##...##.....
#.#...#..#####.#...#..#.....#..
..#.....###...#.........#.#...#
....#.##.........#.#.....#.#.#.
..........##...#....#.#.#.....#
...#...........#.....###.......
#....#..#...#.....#.......#....
.#.#.....#..##..##..#........#.
.#.#.....#....#...#.#.##.......
....###...#...###.##....#......
...#.#.##....#...##......#...#.
#....#...##.....#.##.#.....#.##
.#.#.....##.##.##..###...#.....
.#.#......#..#..#........#.#..#
........#...##........##...#...
.#..#.#.#..#.....#....#...#.#..
#......#...#.#...#..#.#..#.....
.#......#.....#.........###.#..
#..#..........##..###.......#..
#..#..#....#......#......#.....
......#.....##.........##....#.
#..#.#...#...#.##.#..#..##.....
....#.#....###..#.....#...##.#.
..##.....##.#..#..##..#.#......
.........#..#....###...#.#....#
.........#...#...#...#......##.
.......#..#.....#.#.#...#...#..
............#.....###......#..#
#....##..###.......#...##....##
..#.##..#####..##.#...#......#.
#.#..#...###.............#.#...
##...#..#..#.#....#.#.......#..
.....#....##.....###.##..#.....
......##..##..#.#..####.#......
..#...#.#....#...#.#.........#.
##.....#.#....#..#..##........#
...........#..#........##..#...
..##.#...#.#.#..##..#..#..#..##
..........#.###.....#..#.....#.
......#............###..##.##..
.#.......#..#...........#.###.#
#...#..##............##.......#
.###..#...#.#....#....#......#.
..##.........##............#.#.
.##.......##....#.#.#....#..#.#
#.##........#.....#.##...#.#...
#......#....#.#......##....#..#
#.##..##..#...#.###......#.....
..........#.#....###.#.....##..
#..##...#.###..#.............#.
.#.#......#.##.#...#....#.....#
.##...#..##...#...........#.##.
.##..#.#.#..#.....#.....###....
.#...#.#.#..#..#....##...#..#..
#.#.#....#.....#..#..##..#.#...
......#..#...####..#.........#.
.#.#..#......#...#..####.....#.
...#.#...#...#....##..#.#.#.##.
...#........##.............#.#.
...#...#...#.......#..#.#.#..##
.####.#...##......#.##.##.#.#..
#..###...........#..#.#...#.#.#
###...#.#..#...#.#...#.#..#.#.#
#....#.....##...#.#...#..#.#...
.#........##.##....##..#..#....
.#.#.#..#........#...#..#.#.#.#
#.##.....#.#...#....##...#..#.#
..#.......##.#.###............#
##....###..##.........##..#.#..
...##...#...#..###.#.....##..#.
###.................#.#..#.....
....#......#.....#..###......##
.......#...##..#...............
.#.....#..#.....#...##...#...##
.....##....#.#..#.##.....#...#.
#..####.#....#..#.....#....#..#
..#..##.#.##......#..#.#....#..
..#.#.#.#.....#...#...#..#.....
.#........#.#...#.#..#...##....
.#...#.#...#..#.#...###...#.#..
#.....#...##..#.....#...#.#..#.
...#....#................#.#...
......##.#.#..........#...#....
.##..#.#.#...#..#...####.#.....
#......#....#..#.......#.......
.#........#.#.#....###.#..##...
....##......#.....##...#...#...
..#..#.#.#...#..#.####.##......
...#........#.#.##.#..#.##.#...
.#..##...#...#...##.......##.#.
#...#.#......#.................
..#..#.....#....##...#..###....
.#...#.........#.#.##.#........
using System;
namespace adventofcode
{
class Program
{
static void Main()
{
var input = System.IO.File.ReadAllLines("input.txt");
var lineLength = input[0].Length;
const int right = 3;
const int down = 1;
int trees = 0;
int positionCounter = 0;
Console.WriteLine(input[0]);
for (int i = 1; i < input.Length; i += down)
{
var currentLine = input[i];
var currentLineChars = currentLine.ToCharArray();
var newPosition = positionCounter += right;
var currentChar = currentLineChars[newPosition];
var isTree = currentChar == '#';
if (isTree) trees++;
currentLineChars[newPosition] = isTree ? 'X' : 'O';
Console.WriteLine(currentLineChars);
if ((positionCounter + right) >= lineLength)
{
positionCounter -= lineLength;
}
}
Console.WriteLine(trees);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment