From 5598936603aca0f08a472c2ce3089db126861641 Mon Sep 17 00:00:00 2001 From: Patrick Michl Date: Thu, 3 Dec 2020 10:52:37 +0100 Subject: [PATCH] Solution for Day 03 --- day_03/first.rb | 12 ++ day_03/input | 323 +++++++++++++++++++++++++++++++++++++++++++++++ day_03/second.rb | 23 ++++ 3 files changed, 358 insertions(+) create mode 100644 day_03/first.rb create mode 100644 day_03/input create mode 100644 day_03/second.rb diff --git a/day_03/first.rb b/day_03/first.rb new file mode 100644 index 0000000..7497f09 --- /dev/null +++ b/day_03/first.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +input = File.readlines './input' +width = input.first.strip.size +count = 0 + +input.each_with_index do |row, i| + next if i == 0 + + count += 1 if row[(i * 3) % width] == '#' +end +puts count diff --git a/day_03/input b/day_03/input new file mode 100644 index 0000000..1016b75 --- /dev/null +++ b/day_03/input @@ -0,0 +1,323 @@ +...#...#....#....##...###....#. +#.#...#...#....#.........#..#.. +.#....##..#.#..##..##.......... +.....#.#.............#..#...... +.......#...#.##.#......#..#.#.. +#.#....#......##........##..... +.....##.#....#..#...#...##...#. +...#...#..#.......#..#...##...# +..........#...........##....... +..#..#..#...................#.. +#..#....#.....##.#.#..........# +.#.##.......###.....#.#...#.... +.#..##....##....#.......#...### +#.#..##...#.#..#............... +.........#....#.......##.#.#... +...###...##....##...#..##.#..#. +....#.........#..#...#.......#. +....................#..#.#.#... +..#....#..........#...........# +.#.....#..#.....##........##..# +#..##..#...##............#..##. +.#..##....#..........#..#.##.#. +..#####..#.#............##..... +...###.#....##..#.#....#.....#. +.#.......##....#...#.#.....##.. +...#....#...##.#...#..#........ +.####.....#....#.#.#...#....... +...#....#.....#.......#........ +#..#.#.......#...#............# +...#.....###.##....#.#.###.#... +.#.........#.......#.#....##... +#.#..#...#.#...##......#..#.... +.....#...#..#.#...#..###..#.... +......#.........#...###........ +.....#..##...#..........#.....# +..#..#.#.##.#...#....#....##..# +##....#.##...#.##.#..##....#... +.....#.#.#.#..#....##.#...#.#.. +.....##.......#........#....... +...#.#.....#...#...##.#......## +........#..#.#...#.#.....#.#..# +#..##...#.#...##..##...#.#...## +.##.#.#..#...#.....#.#.##.#...# +.#.####.........##.........#..# +.##..............#....#...#...# +......#...#..#...#..#..###.#... +.......##...#.#.#..##..#......# +.....#....#..##..#.........#... +.....#..#.#.#........#.#.####.. +#..#.......###....##........... +#..##..........#.#......#.#.... +.....##........#...#..##....... +###...#.##.#.#.#.#.##...##..... +....#...#........##.#.##..##... +.#..#.#.#......#.......##..#..# +.#...#.................#....#.. +.##..#..........#..##.......#.. +.#.#.#.....#..#.#.........##..# +...#......##...#.......#...##.. +##...###....#.###.............# +#.....#.#..#.#..#........#.#.#. +.....#.#......##..#.#.....#.##. +.......#...........#..#.......# +..#....#.#.#......#.....#...#.. +.....##........#..##..#..##.... +#.#........#...##....#.#..##... +#......#......#....#..#...#.##. +....#.#.......#.#.#............ +......####.#.##...#.#.##.....## +..###.#.#..#.........#.####.... +.#.......#..#.#....#.#..#.#.##. +#....#....#............##...##. +....#....#............#....#..# +..#........#..#....#..#..#...#. +.#......##....#..........#....# +#.##.....#..........#.###.#.... +....##...#.....#.#......#.##... +#.#.....#.......###.###..#..#.# +..###..##.............#.####.## +#....#.....#....#..##.......#.. +.....#....#...#.#.#.#..#...#.## +...#.....#..#....###......#.#.# +##.........#.#..#..#.#..#.....# +.#.....#.#....#.........##..#.# +.#.#..#.###..#..#..........#... +.##....#.#.#...#......##.....#. +#.#....#....#...#...##...#..#.. +#...#........#....#....#......# +#......#...#..#.#.##.....##..#. +....#...#......##...#..#....#.. +.#......##.##.......#.......#.. +.#...#..####...........#.#.#... +.........#...#.#.........#..... +#.##.....#.#..#.#.###...###..#. +#...##.###......#.###..##.#.##. +...##.#.....#....#..#......#... +#....###.#..#...##.....#......# +........###...#...#............ +........#....#...#...#....#...# +#....#..#..#....#.#........#.#. +##...#.....#.#..........#..#..# +#.#...##.....#........#...#...# +##.#.#.......#...#..#.###....#. +.#.......#....##..##...#.....#. +#....#....#.....#.......#...... +.##.##.##...##...#.#.#..#..#... +#..#..#.##....#......##....###. +.......#.#.........#..##.#...## +.#..##...#....#.....#.......... +..#.#...#......#.#..#.......... +.##....#.#.#.##.......###...#.. +..##.#...#.#.#.#.......#..#.... +#..#.......#...#........#.....# +.....#.......#......###..#..... +...##.#.......#.....##.....##.. +##..#.......#.#.....#....#..... +..#....#.##.##...#...#......#.. +.#..#.###.#....###........#...# +....##.##...##..#..#.#....#.... +..###...##.....##.............. +#....#...##...#....#..........# +.##........#......##...##...#.# +..#.#.##..........#......#..... +...#...#.........#.##........## +..#.#..#.#..#...#....#...#..... +...##...#..#.###.#..#.#...#.... +....###........#..#..##...#.... +#.#....##.......#.#........#... +.###...#..#.#.#.#..#...#..##.## +..#.........#####.#......#..#.. +#.....#.....##..#....#...#...#. +...#..#....##....##.....##.#... +.........#............#.##..... +....##.#..#....#.##.......#..## +.###....#.#..#......#.#.......# +.###...###.#.........#.#..#...# +.....#........#..#.#..#.#..##.# +.###..#....##.........#..##.... +..#.......#..#..##...#.###.#... +#.......#...........#.#...#.### +#.##.##...##.#...##..#.....#... +..#..#........###.#.....##..... +#.....##....#...##...####..#..# +....#........#...#...#......... +......#.#.#.#.......#..#.....## +..#..#....#.....#.#...##......# +..#....#...#.###.........#.###. +...#......##..#.#.....#...#.... +...#.......#...#...#........##. +............#...#..#....#.....# +....##......................#.. +#.#.#....#....#..........##.... +#.#.....#.#.##..#...#.##....##. +...#...#..#...#..#.#.#.......#. +#.....#..........#.........##.# +#...##..#..#.#.......###....#.. +.#...#..##....#.....##.......#. +....#.##.....#.........#.#....# +........#.#...####..#.......#.# +.####...#.#......####.....#.##. +###..#....#..#.......#.#..##..# +#......#.#....##..#.##.#....#.# +...###...#...#..##.#..#..#.#... +...##..##....#..#.....#........ +.....#..............#......#..# +......#....#......#..#......... +#..#.....#.##...........##..... +.#..#.#..................##.... +#.#..#..##...#....#.#......#... +.##.#.##......#.##...#...#...#. +..#...#.........#.#..#.#....#.. +.#.####.#..#.#......##.#..#.... +#..#.......#....#.............. +....#............#..#.......... +.....#####.....#.....#..##...## +#.#....#.#...............#..##. +.#.#..#...#......#.....#.#.#... +.#....#.#.#......#.....##....#. +....#....#.##..#.......###...## +.....#..#.##...#...#...#..#.#.. +##..#........#.#..#..##......#. +.#..#..##.......#..#.....#..... +.#.#.....###..##.#.#........... +..##..##.####..........#..#.... +..##..#..#...#....#......#.#... +#...#.#......##.....##.#..###.. +#..#..............#........##.# +.........#.##..#.#..#..##.##.#. +#....##....#.#..#.#...##..#.... +.#....#.......#............##.. +.......#.#.......#...#.#......# +......##...#.......#.#........# +..###..#.#.##....##...#....##.. +..##.##..........##..###....... +.#.#.#..#..#.#.......#.#...##.. +..#..##.........#.###..#......# +....#.#.#...##.#...#...##..###. +..###..##.........##...#...#..# +.#..##...#.......#.......#..#.# +........##....##....#.#.###.#.# +#.....#.#.................#.#.. +....#.#.#.....##.####.#......#. +....#.......#.#.##.##.......... +...#...........#...#.##...#.### +#....#....#..........#.##...... +##..#...........##.....##.##... +.#.##...##..##....#..#.....#### +#...#...#.##..........##..##... +....##..#....#.....#.#...#....# +..#....#..##...###.#.#......... +#......#.#.#...#...#.........#. +#............###.#.#.#..##...#. +.##.....####...##..##..#..##.#. +#..#........#.....#.#.....#...# +#............#....#.#.#........ +......##...##.#....#.....#...#. +..#........##......#.#.....##.. +.#..#..#.....##.......#..#.#..# +.#....#..#....##.#.#.#..#..#.## +.####.#..........#...#..##..... +...###..###...##..#............ +#..#.....##.#...#..##..#....... +.....##....#...###.##...#...... +...##..#...#..#..##....##....#. +...###....#.###.#.#.##....#.... +##.#.#.....#....#.#....#..#.... +.......##.....#.#..##...##...#. +.#....#.#...##.#..#....#.....#. +..#...#..#...#.##........#...#. +#....#......##.#....##...#.#..# +.....#..#..#..#......#...#.#.#. +..###....#........#...#.......# +###...#.......#.#.......##.##.. +......##.....#.#........#....#. +#.##..#.#.#.#..#....#.##.....#. +..........#.##.#...#...#..#..#. +..#...##.#..........#..##.###.. +..###..##.##..#.#...##.####..#. +#.#.#...............##....###.# +....#.........#.#....#.#....#.# +..#...#.###...#....###.....#... +..#..#....#...#............#... +.#..#....#..##.....##.......... +..#....#.#...#.#.#.#.......##.# +.........#....##........#.#.... +...#..##.#..#.##...#...#.#....# +....####...#...####.#....###..# +......##...#.##.#.......#..#... +#.#...#.#...#.#...#....#.#.#... +.#.....##...#.....###.#....#... +......##.....###...#.#...#.#... +#..#..##.#.#......#....#..#..#. +....#.###.....#..#...#.##.....# +##.##........#......#....#..##. +##.....##.#.....#.....##.....#. +.....#.##...#.#..#.#.#.....#... +.#.##..#...#.#..#.....#.#...... +.....##.......#..#...##..#..#.. +#.....#..#.####......#........# +.#..#..##.#..##............#..# +.##..#.#....##.##.....#......#. +.......##.........#..#......... +.#...#.......................#. +#......#.#....##.#.......#..#.. +..##..##......#.......#....#.#. +##......#......##...##......... +..#....####....#.#.....##.#.#.. +..........#..#.#.#.....#..#.#.. +##..##...........##.......#.... +##....#.#....#..#......###....# +...#.#.#..#.......##.......#... +#....#.......#.......#......... +...##......##....#...#......#.# +#......#####.#.........#.....#. +#..#.............#..#....#...#. +.......#.##..#..#..#..#....#### +......#.##..##..........###...# +.#.##....###..#........#....##. +#......#..#...###.#...#.....#.. +.#.#.......#....##.......#.#... +..#.##..#..##.....#.........#.# +#.#...#..#.##....#.......##.... +.#.....###....#.#..#...#.....#. +#...#..#.......#.#.....##...#.# +#.#####.........#....##.....#.. +#....#..##...#....#.##.......#. +.#.#.........##....##....#..... +...#..##.......#....#.#.#...... +#.###.##...###....#.....#.####. +.#...#.#.#..##.#..........#.... +#.#.....#.##.#..####.....##.#.. +...###.##..####.......#......## +.##..#.........#...#.#.....#.## +..#.....##....###.....#.#...##. +#....#....#..#....#.##......... +......###....#.#..#..#....##... +.#.#................#.......##. +...#.......#.........#.#....... +...#..........#...##.....###... +....#......#...#............... +.##...#....#.....#.##......#... +.#.....###...##..##...#.#...... +....##........#.....#...#....#. +#.........#.#...##...#.#..#.... +...#.#.....#.#........#.#....#. +.#........#.....#.#.#.#.#..#... +....#...#.....#.#....#........# +..###.#....#.#....##...##..#.## +.#....#.#.####.#.#.....#....... +.#...#...#.................##.# +..................##..#..#.#.#. +.#..#............##....###..... +.......#....#...........#...... +....#.#.#.....###.........#..## +...#.#....#.#.##.#.##.....##..# +.#.##.#...##...#.......#.....## +.#............#...#..##...#.#.# +#.##..#.##..#..##.###.#........ +..............##....#...#..#.#. +.#.#...#.#....#....###........# +.#....#.#....#......###........ +..#.......##......#.##.....#... +.....#......#..#...#.#.....#... diff --git a/day_03/second.rb b/day_03/second.rb new file mode 100644 index 0000000..6307390 --- /dev/null +++ b/day_03/second.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +input = File.readlines './input' +width = input.first.strip.size +output = [] + +[ + { r: 1, d: 1 }, + { r: 3, d: 1 }, + { r: 5, d: 1 }, + { r: 7, d: 1 }, + { r: 1, d: 2 } +].each do |dir| + count = 0 + input.each_with_index.select do |_, i| + i % dir[:d] == 0 + end.each_with_index do |row, i| + count += 1 if row.first[i * dir[:r] % width] == '#' + end + output << count +end + +puts output.inject :*