From 58f799eff677f5ee2e91269ef6fbaefccc363979 Mon Sep 17 00:00:00 2001 From: Jan-Lukas Else Date: Thu, 3 Dec 2020 08:21:45 +0100 Subject: [PATCH] Day 3 --- 3/input.txt | 323 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3/main.go | 67 +++++++++++ 2 files changed, 390 insertions(+) create mode 100644 3/input.txt create mode 100644 3/main.go diff --git a/3/input.txt b/3/input.txt new file mode 100644 index 0000000..90141e9 --- /dev/null +++ b/3/input.txt @@ -0,0 +1,323 @@ +....#..#.......#........#....#. +..##.#.#.#...................#. +....#.#.##..#....#......#...... +.........#.#......##.....#..... +..........#.###.##...##........ +#....#.#.......##.....#..#..... +#...........#.#...#..#..##.##.. +......##.............#.....#... +..##..........###..#.#..##..... +...........#........#......##.. +..##...........##.............. +..#......###.#.....#.#.#....... +..#..#..#..........#.#....#.... +.#.....##...................... +...#...##..#...#.........#..##. +.#......#..#..#...#......#.##.. +..##.##.......#..#.....#..#...# +..............#..#..#...#...... +...#...#....##.....#...#...#... +......................#...#.... +.......#......#...#..##...#.#.. +##......#..#.....#....#.....#.. +....#.#.##.#.#....#............ +#.....##.............#......... +..........#...........#.#.....# +...#...##....#.#........#..#... +................#..#.##.##....# +......#...#...##...##....#..... +##....#..#..#...#..#........... +#..................#...#.#..#.. +....##....##.#....#..#......#.. +.....#...........#.........##.. +..#..............#.........#..# +......##....................#.. +..#.....###...####...#...#.##.. +#..#.#......#.....#.......#.#.. +##.#.........######........#... +..#....###...#.#..............# +.....#..............#.........# +....#......#..#.........#...#.. +.....###.....#.###.......###... +#.#..#.....#....##...#........# +..##....#..#.........#...#.#... +..#..##.............#....#.#.#. +..##.#..#.#.#.........##....... +#.#..#.........#..............# +#..#.........###.......#.#..#.# +.............#...#....#......#. +..........#.#...##.###.....#.#. +..#.....#...................... +.......#......###.#.......#.... +....#....#.........#...###.#.#. +.#.............#............#.. +....#..#.............#.#....#.. +....#.....#...#...##.#......... +..#...#...#..................#. +........#....#.....#........... +.....##.......#...#.#..#..#.... +...#............#..#.#......... +......................#........ +....#......#.....#.#....#...... +.....#..#.........#.........##. +...............#.....#....##... +...#.#.#...#..#...........#.... +.#....###......##...#.#.#.#.... +.....#...#....####....##....... +..#......#..#.....##.#...#..... +...#.##..#....#..##.....#...... +..#......#...#...##.....#...#.. +......#.....#........#......... +..#.#....#..............##....# +..#...#......##............#... +.##.#.......#.......#......#..# +...##.##...#.....#.......#..#.. +......##..#....#.......#....... +.....#..#..#.#.....#.....#...## +##.#...#.#.#.....#...#.#.#.##.# +...................###...#..#.. +.#.....##.#......#........#.... +.##...##.#..........#...#....#. +......#..............#.#......# +...#.......#..#...........#.... +.###...#............##..#...##. +##..#.#.........#............#. +#...#.#......#.##...........#.# +.#.#...#........#......##...... +....#...#...#.....#...#....#... +...##...........##.........#... +.........#...#..###............ +..#........#...............#... +.............#....#.#.......... +........#......#.#.......#....# +.................#....##.#.##.. +..#...##........#.............. +#..#........#...#....#......... +......#.#.....#.....#..###.#..# +....#............#...#.#.#..... +............#..........#...#... +..........#....##.#.........#.. +..............#...#...#..#..... +#......#....#..##....#......##. +...#....#.................#.... +.#.##.............#...#....##.. +....#..#.........#..#....#....# +..#.....##..#......#.#..#...... +..#..#.....#........#...#..#..# +.........##.#.##.#.......#....# +..#.......##.##...#.....#.....# +.............##...#...........# +..#......#..#....#...#..#.##... +....#........#......#.........# +.......#........#..#.#.#..##..# +..#......#...........##...#.... +.....#..#.#...#..............## +.#..#......#......#........#..# +...##...............#....#..... +.......#...#.......##..#....... +.....#....#...#...#..#.....#.#. +...#.........#.....#........... +...#.....###....#....#...#...#. +#..#.....#.........#.........#. +.................#.#.....#....# +...........#..........#..#..... +........#.#....#...#..#.....### +#............................#. +..##..#..#...##.........#...... +......##....#.#...#.........#.. +......#..##.#......#..#.....#.. +...#.......##....#.#....#...... +.....#........#...#............ +#.......#...#.........#......#. +......#......#....#..#......... +..#.#........#..#......#....#.. +.#..#.#..........##....###.#..# +...#....#.##..#...#....#....... +..#.....#......#.###.......#... +..............................# +.....#..#...#...........#...... +.##...#....##....#.#.#.#....#.# +.#...#....#...#........#....... +....#............#...##..#..... +....##..#....#....#.....#....## +.............#..##.#.#.#....... +#.......#.#.#.......#..#..#.... +#..#...........#.......###..#.. +.#..##.#.....#........#........ +..#.#.......#............#..#.. +...........#..#............##.# +.....#.......#.....#..#.##.#..# +......#......##.....##......... +..##.#..#.#..#..#.............. +.....#.............##...#.#.##. +.#......##.#..........#........ +..#..#.........#.....#.#.#..... +..#.....#.......#.....#..#..... +#.#.#........#.#...#....#..#... +.#.#.......#............#....#. +......#..................#....# +.#...#...#.....#.#..........#.. +.#..##....####...........#.#... +..##.....#...#.#....#....#..... +#.....................#....#.#. +###..###.#.#...........#.....## +......#......#..........#...... +...#......#.##.....#......###.# +.............#..#.#...........# +..#.............#.#..#.....#... +...#...............#....##...## +........#.................#.... +#..###.....#.......##.#......## +....#.#..............#......... +#..........#.....#..##...#..... +................#...#..#....#.. +..#...#....##..........#.#..... +......#........##......#..#...# +...#....#..#.....#.......#...#. +.#.....#..#...#..###....#...... +....#.........#....#.#.#.....#. +#.#....#...#....#.....#..##.... +.......#..#..#..........#...#.. +..#.#..#.....##.#.#............ +..#....#.....#..##..#..#.#..#.. +..#.##.#...........#...#..#.... +.........#........#...#........ +..#.#.#.......##.........#.##.. +#.#..........#.#...#..#......## +.#..#....................#.#... +.##......#................#...# +..##.#######......#....#....... +....#...##.#....#.#............ +.##....#...##.......#...#..#... +...........#...#...#...#..#.... +#...#.....#.......#....#.....#. +.............#................. +........#.#.......#...#.#.#.... +..............#............#.#. +......#......##..#.......#....# +##...#..................#...... +.....#......###.....#.......#.# +.....#.#............#.#........ +..#.#..#............#....#.#... +##.#.###.#.#.#..#......#....... +...##........#..#.....#.#.#..#. +##......#.##.....####..#....... +............#...#..#...#..#.... +...#..#................##.#..#. +.#....#.#...........##.#.#...#. +####..#...........#.......###.. +.......#.................#..... +.......#....#.......##....#.... +..#.........#...#....#......... +..........#..#...#.#...##..#... +....##..........#.........##... +#.........##..#.#..#.......#... +.#...........#....#...#...#.#.. +....#..#.....#...##....#.#....# +.#....#.....#......#..##.##.#.# +#......#..#.......##........... +...#..#...#.#.................# +......#.......##....##.#......# +....#....#.#.#.....#....#....#. +..#..........#.##...##..#...... +...#..#........#....#.#..#....# +##.......#........#..........#. +.#........#.......#...#..##...# +..#..#..##..#...........#...### +..#......#..........#..##...... +.#.....#..#.#...#...#.........# +#.#......##.................... +#...#.....##...........#....... +........#...#....#.......##.... +...#.##...#....#....#..#..#..#. +...#..#......##....#..#..##.... +#...#..........#.#............. +##..#........##.....#.........# +.....#......#.#...###..#....... +#..##.#..#.###...........##..#. +.....#....#..........#.......#. +##.........##.#................ +....#.........#............##.. +.......#........#......#..#..## +.#...#...##..#....#..#......... +.............#...#.#........#.. +......#..#...#..#.###..#....... +........##.#..#.#..#..#........ +#.##..#..#..........#...##..### +.##...#............#.#...##..#. +................#....##.#...#.. +#.................#..........#. +...#..#..#..................... +..#...##.#.#................... +.....#...#.......#............# +..#..#.........#..##.#..#.#...# +.....#.#.....#.#.......#.....#. +..................#..#....#.#.. +..#.....###.##.......##....#.#. +..#......##.......#....##.#.... +....#...................#..##.# +.......#....#.##.#.......#....# +..#...#......#..#...###....#.#. +..#..#.#....#...........#.....# +.....#..#..#.......#........#.. +......#.##.#......#...........# +#...#....#.#..##.##..#..##..... +#...##....#.#...##........#.... +..##............#.#.#.......... +....#.....#.#..#.......#..#.... +#..#.#.....#..#..##...#..##.... +...##........#...........#...#. +.####......#..##.........#.#... +.......#....................... +.................#....#..#..... +.........##......###........... +.##......#.#.#....#.#...#..###. +....#......##.###.#.#..#....... +..........#.......##......##..# +...........#.......#..##....... +.....###..#..............##.... +........##..#.#.#......#....#.. +#....#......................... +...........#...............##.. +......#.................#...... +.....#...#..##...##...#...#.... +..........#.#...##.####......#. +..#.#.....##....#...........#.. +..........#....#..#....##...#.. +.#.......#..##...#...#.....#... +...##....#.#......##...##....#. +#.......#.......#.##.#...#.#... +#...#..................#......# +..#.......#...............#..## +#.....#..................#....# +.##.....#.....#......####.....# +..#........#...#.#........#...# +..##.....#....#...#...........# +..#..#.....##..#.##...#........ +..........###..#....##.....#... +...#...#....#.##.#...#.#....... +..##......#.......#.......##... +............#............#..... +.##....#.........#............. +....#....#....#........##...#.# +.......##...................... +..........#.#.................# +......##.#...#.........#.....#. +..#...#......#..#.............# +..........###.#..#.#...#..#..#. +#..#.#..#....##...#...#.#...#.. +.#........##...#......#.##..... +...###.#...##..............##.. +#.#.#...#...#..#....#.#..#..... +.#.#.##..#....#......#.#....... +...#..#.#....##...........#..#. +.....##..##......#.#........... +......#.....#....####....#..... +.#.#.#...#..#..#...........#... +.....#......................#.. +.........#.........#.###.##.... +.....#......##..........#...... +..#...........##...........#... +..............#.........#.....# +..#....#..#...#...##.#......... +.#.#.#....#..........#......... \ No newline at end of file diff --git a/3/main.go b/3/main.go new file mode 100644 index 0000000..9d83edb --- /dev/null +++ b/3/main.go @@ -0,0 +1,67 @@ +package main + +import ( + "bufio" + "fmt" + "os" +) + +func main() { + file, _ := os.Open("input.txt") + defer file.Close() + + treeMap := [][]int{} + + scanner := bufio.NewScanner(file) + for scanner.Scan() { + treeRow := []int{} + for _, char := range scanner.Text() { + if char == '#' { + treeRow = append(treeRow, 1) + } else if char == '.' { + treeRow = append(treeRow, 0) + } + } + treeMap = append(treeMap, treeRow) + } + + rowLength := len(treeMap[0]) + + row := 0 + pos := 0 + trees := 0 + + // Part 1 + + for row < len(treeMap) { + trees += treeMap[row][pos] + row++ + pos += 3 + pos %= rowLength + } + + fmt.Println("Part 1:", trees) + + // Part 2 + + trees = 1 + + type slope struct { + right, down int + } + + for _, s := range []slope{{1, 1}, {3, 1}, {5, 1}, {7, 1}, {1, 2}} { + slopeTrees := 0 + row = 0 + pos = 0 + for row < len(treeMap) { + slopeTrees += treeMap[row][pos] + row += s.down + pos += s.right + pos %= rowLength + } + trees *= slopeTrees + } + + fmt.Println("Part 2:", trees) +}