From f3da58723c2c399115414dfbd695af8b7e8c3a14 Mon Sep 17 00:00:00 2001 From: Karl Spickermann Date: Thu, 3 Dec 2020 19:47:26 +0100 Subject: [PATCH] Day3 --- day3/day3.go | 40 ++++++ day3/day3Input.txt | 323 +++++++++++++++++++++++++++++++++++++++++++++ day3/day3Test.txt | 11 ++ 3 files changed, 374 insertions(+) create mode 100644 day3/day3.go create mode 100644 day3/day3Input.txt create mode 100644 day3/day3Test.txt diff --git a/day3/day3.go b/day3/day3.go new file mode 100644 index 0000000..39a37c3 --- /dev/null +++ b/day3/day3.go @@ -0,0 +1,40 @@ +package main + +import ( + "AoC2020/helper" + "fmt" + "os" +) + +func main() { + args := os.Args[1:] + input, err := helper.GetInput(args[0]) + if err != nil { + fmt.Println(err) + } + fmt.Println(day3(input, 3, 1)) + fmt.Println(day3Part2(input, [][]int{{1, 1}, {3, 1}, {5, 1}, {7, 1}, {1, 2}})) + +} + +func day3Part2(input []string, slopes [][]int) int { + result := 1 + for _, slope := range slopes { + result = result * day3(input, slope[0], slope[1]) + } + return result +} + +func day3(input []string, right int, down int) int { + count := 0 + x := 0 + y := 0 + for y < len(input) { + if string(input[y][x]) == "#" { + count++ + } + x = (x + right) % (len(input[0])) + y = y + down + } + return count +} diff --git a/day3/day3Input.txt b/day3/day3Input.txt new file mode 100644 index 0000000..147a37c --- /dev/null +++ b/day3/day3Input.txt @@ -0,0 +1,323 @@ +.#.#....##.......#..........#.. +...#...........##...#..#....... +#.####......##.#...#......#.#.. +##.....#.#.#..#.#............#. +##.....#....#.........#...##... +###..#.....#....#.............. +..........#..#.#..#.#....#..... +##.....#....#.#...#.##......... +#...#......#....##....#..#.#... +.##.##...#....##..#.#.....#...# +.....#.#..........##.#........# +.##..................#..#..##.# +#.#..........##....#.####...... +.#......#.#......#.........#... +#....#..##.##..##........#.#... +##..#.##..#...#..####.#..#..... +###....#.###.##...........##..# +.....#.##.....##.#..#####....## +....#.###....#..##....##...#... +..###.#...##.....#.##..#..#.#.. +#...#..#..#.........#..#....... +##..#.#.....#.#.#.......#...#.# +...#...##.#........#...#....... +..#..#.#..#...#...#...........# +........#.....#......#...##.... +#........##.##.#.#...#...#..... +####.......#.##.###.#....#..... +...#...........#...#......#...# +##...#...#............#.......# +....#...........##.......#..... +###......#.....#....#...#.#...# +.....##..........#.......#.#... +##.##.##...#......#....#....... +##..#.#..#......#...#..#....... +....#....##.##............####. +..#.###..#.##.###..#.##.......# +#.##..#.#.....#..#.....##...... +..##..#.....##.#.##........#... +.#..#.#......#..#............#. +.....#..#.#...#....#.##.#...... +.#...##.#..#.#...##...##..##... +###............#.#..#..#...#... +..#..##.####.#.....#.....##.### +#....#.##..##....#..#...#.##.#. +.....#.##.........##...##...... +.........####.#....#.#......#.# +.........#.#..#...#.#..#.#....# +.#.....#..##.##..##....#....... +..........##......#.##.###....# +.##...###..##.#...#........##.. +..............#.#....#.#.###.## +..##.##.......#.#......##...#.. +.#.....#..##..#.###...#..#.##.# +#.....#.#..#...#........#...#.. +.#......#....#.#.....###...#..# +..##.#....#..##......#.....#... +..#.#.##..#.....#.####..###.... +.........#......#..#........... +..#........#.##.#.....##.##..#. +.......#.........#....#...#.#.. +.##.....#.#....#.#.......#..... +..........#.##........##...##.. +###..###.#.#..#..#####.##.#.##. +..##..##.#.#...#..#.#.#......#. +#..#..#..#..##..#.....#......#. +..#....#.##..#......##......... +..#.##......#...##.#......#.... +.......#..#.##.#.....#......... +.......#.#.#.###...##......#... +.....#.#..........#..#...#..... +....##..........#..........##.. +..#......#.....#.##.#..#...#.#. +....#.....#..#...#..#.#.##..### +.####....#........#...#........ +...##.#.##.#..#...##...#.##.... +....#...#...#.#.#.#...#..#..... +.....#...#.#.....#.#........##. +..#.#.......###.#.....##....... +......#.........##....#....#..# +.............##.....##......... +.........##...##.......#.....#. +##.........#..........#.###..## +...#.....#......#....#..##..... +##..#...#...##.#.....#.#......# +..#...##.#.......#.#......#.##. +......#.......#.#...........#.. +..........#.....##............# +#........#...#..#.......###.##. +.##...........#.#........#.#.#. +...#..##...#.#....#####.#...... +.....##...###...#..#.##...####. +...#....#.....#..#.......#..... +#....#....#...#..#..#.######..# +#.###...........#......#...#..# +.#.#.#.#..#....#....#...##.#... +.#..#.........#.#....###...#... +......#..##.##..........#....## +.....#......##....##.....#...#. +.#...#.#.#....##....#..#....#.# +..................#..###.#..##. +..#.........#......#....#..###. +#.#.....#..#..#....###..###.... +..##..##.#..##........##...##.. +##..#........##..###..#.....#.# +..#..###..#......#....#...#...# +#..#.#..............##.#..#.#.. +.....####....#...####.....#.#.. +.....#....##.#......###........ +##.##...#.#.#.#.......#....##.. +.#......#...#.#....#..##.#.##.# +#.#.##.#.#......#..##........## +...##.....#.....#...#..###...#. +........###.....#.....#...##..# +.....#.##.##......#.#....#...#. +.#....##.......#..#.####....... +.#..#....#..........#......#.#. +.#.##.##.....###.#.#........... +.........#......#..##.......... +....#...##.#.#.#..#.#.........# +..#.....#.##...#..#..#.###....# +...#.##......#.....##....#..... +###............#.#....#...#.... +.......#.....#..#.#.#....#..#.# +...#......#.#..##..#....#...#.# +............##........##..##... +..#..#.##..#......###..#....... +........#.........#............ +..#...#.#########.#...##..###.. +#....#......#.......#.#.....#.. +#.#..#....###.###....#...#.#... +#...###.#.#.......#.##......#.. +.................#...#.#.#..... +##....#...#........#....#.#..#. +......#.....#...#..........#.#. +##..........#...#..........#.## +..#.#.##.#....#.#......#...##.. +.....#.......#..#.....#........ +#.##.#..##..#.......##......... +....#......#..#..#.#...#....... +...#....#................###... +.##.....#.#....#.#..........##. +...#..#....#.##.##......#...... +..#.#....#.......#.#..##....... +....#.....#..........##.#.##### +#.....................##..#..#. +.###..#.##.......##.#...#..#... +...###.......#..#...#......#..# +#..#...#.#..#.#..#..#.##....... +#...##.......#..#..#.##..###... +......#....#.#.#........#.##..# +..##..#....#....#..#.#..#...... +..##.#...#.#######..#...#.....# +..#....#..#.........#..##...... +...#....#.#......#..#..#.#..... +#..#....#........#.#..##....### +#....#..##......##.##.....#.### +...#.#..........#..#.#.#.#.##.. +......##..#.#..#.#....#....#... +##....#....#..#..#.##......#... +....#.#..##.#.#...###....##.#.. +...#.......##..#.......#...#... +......##.......#..##.....#...#. +...#.#...#...........#...#..... +.#....#...#......##.##..###..#. +.#..........#...#...#...##.##.. +.....###..#.....#..##....#.#### +..#.###..#..##..##.....#.#..... +.............#.###...##.#.....# +....###.......###.#.....#..#.#. +........##.#.........#.....###. +.....###.#..#.....#...#..#..... +.#....#..##.#..#.#....#.......# +........#......#.#..#.#..#...## +...#.##.##......#.............. +.#.....##.#.....#..#......##... +#..#..#.....#.....#.....###.... +.##...........#..#.##.....#.... +..#.#......#.#...#.##.#..#...## +...#..........#.....#.......... +#.#.#.#.#...#....#...#.....##.. +#......##...#...#..........#.#. +....##........#.#.............. +#..#.#.#..#........##......#.## +........####...##.#.....#...... +....#........#.#..#..##..#.#... +.#.....#..###...#..#.....#..#.. +#......###.#..#....#..#.#...... +....#.....##.##..#...#.#..##.#. +..##..#...#.#......#....#...#.# +#..##...##..#...###...#..#..... +.......#.....#...........##.... +#..##....#........#....##..#.#. +.#........#..##...###.#..#..... +.#.#....#..##...#...##.#..###.. +#.........#.......#.....#.#.... +#..#.....#.#.###.#..#......#... +....#..#.#....#..##..###....### +###.##.#.#..#...........#.#.#.. +..##.#.......#......#..##....#. +.....#.#.#.......##.......#...# +...........#.##....##.##....#.# +...#.......#..#.##..#......#..# +#.#.#...#......##.#...........# +##........#...........###.#..#. +..........#.#.#....#.#..##.#.#. +...#.#.#....#..........#..#.... +#.#....###.#.#..#.......###...# +.#....#......#.#.#..#..#....... +......##.............#....#.#.# +.#..........#.........#.##..... +##....#....##....#..#.......#.. +#.##.##.#..#..#.....#..#.##.#.. +.#..#.......##..#.....##.##.... +.......#..........#.#.##..#.##. +....#.....#.#...##....##....... +.......#.........#...##....##.# +#.....#......#..........#...#.. +...#.#.......#.#..#....###..#.. +.....#.#.#.........#........... +.#..###.#.#........#.#......... +.........#..#......##...##....# +...###..#.....##.....#.###....# +.##...#...#........###.#..#.... +.##........#..#.###.######.##.# +##.#...#.#....#..##.#....##.... +.......##.....##.#..###.#...... +..##...##........#.......#....# +#..##...#.####...###......#...# +.##.....#.##.#.#.....###.#..##. +..###....#.#.###.#....#........ +....#..###..#...#....#..#..#.#. +#.#.##....##...##.......#...... +.........#...#....#..#......... +.............#...#..##.#....... +...#.##.......#...#.#..##.##... +.####.#.##..#.#......#.##...#.# +.#..#.#.....#.................# +..#.##..###....#...#......####. +..##..##...........#....#...#.. +....#...#...#...#.......#....#. +#.#...###...#...#.#...#....##.# +......#...#.#.......#.....#...# +....##...#.#.#....#....#.#....# +.....#.....#...##..#...#....##. +#.....#....#......##.##....#... +...#.#....#...#....#.#....##..# +...#.#..#...##....###..#....... +...##......###...###.#...#..#.. +##.......#.......###.......#..# +..##.##..###.#............#...# +#.....##..#..##....##..#....... +......#.#...#......#.....#..... +#...........#....#..##.##.#.... +.......#..#......#...#....#...# +.#...##...........#......#...#. +#........#....##...###.#....#.. +.....#.......##.........#.##... +.#.###..#....#..##.#..#.#..#... +#.......#.##.#.#....#.#..#....# +###.....#.#.......#..#......#.# +#..#.#.......#.#..##..##.#.#... +#..#.#.#.###........#.....#...# +#.#.#..#..##.....#...........#. +..#.#..#.....#...#...#...##.... +...#.##......#...##.#...#.#.#.# +#..#.#.#.#.......####.......... +..#......#.#......##.###.....## +..#...##..#.........##....#.##. +##.##.##.#.#.....#..........##. +.#.....###.#..#....#..#.###...# +#...##.......###....#.#..#..... +..#....##.........##.........## +......#....#.##.......#........ +..#.#.#..#...#...#...##.#...#.. +......#..##.#.#.#...##...#.#.## +#..#...##.#.....#...#.##....... +..#..#.........##.#...#.##...## +##.##.#....#.......#.##..#..... +.....##...##.##...##.........## +#......#...#.......#...#...#... +...##...........#...#..#....... +.#.##.#..#........#....#....... +#.#...#..#......##...#.#.##.... +##........####..#.#...#.#.##.## +#..#.#.##......##.#.#..#....... +.....#.........#..#.####....#.. +......##..#....#...#.#....#.... +#...##........#.........#.....# +.#.#...#.#.#..#............##.# +.#..#....#....#.....#...#.....# +..###...#..#.....#.##.###...#.# +.#.###..#..#...#.#...#.#......# +#...#####......###........##... +.....#.....#..#.#....#..##..... +....##...#.#.##.#####...#....#. +.#.#.........##.#.......#..##.. +.#...#.#...#...#....#.#...##.#. +.##...#..#.#..#......#.#.#..##. +..#.....#..#.....##.....#...... +..#........#..##...#.......###. +.#....#.......#....#....#..#... +....#......#.#.#.........#..... +..##...#.#.#...#.#........#.... +.#.....####...##.#..#...##..... +...#.....#...#...#....#....#... +.........#..#.#.....#..#.#..#.. +.........##...........#.......# +......#..#.....##...#.##.#..... +.#......##........##...#.#.##.. +.....#.#..##...........#..#..#. +...#.......#...#.#..#.##..#.##. +...#.......#.....#.#...#.##.#.. +#.....#.............##.#..####. +.#...#......#...##.#....#.#.... +.##..##.##....#.#.....#.......# +...#...#....#....##.#..#....##. +..............##....#.......#.# +.#.#.#...##..#..#...###.#..#... +.#.#...#.#..#.#..#...######..#. +........#......#.#..#.#....#... +..###.....###.#.##....#...##... +.##.#.....#.......##.......#... +..#..##...#..........#.#....#.# \ No newline at end of file diff --git a/day3/day3Test.txt b/day3/day3Test.txt new file mode 100644 index 0000000..8f551de --- /dev/null +++ b/day3/day3Test.txt @@ -0,0 +1,11 @@ +..##....... +#...#...#.. +.#....#..#. +..#.#...#.# +.#...##..#. +..#.##..... +.#.#.#....# +.#........# +#.##...#... +#...##....# +.#..#...#.# \ No newline at end of file