Created
December 3, 2020 05:28
-
-
Save neenjaw/53f69c6e1eaff80f14822387cf36cdd2 to your computer and use it in GitHub Desktop.
AoC Day3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
# lines = <<~MAP | |
# ..##....... | |
# #...#...#.. | |
# .#....#..#. | |
# ..#.#...#.# | |
# .#...##..#. | |
# ..#.##..... | |
# .#.#.#....# | |
# .#........# | |
# #.##...#... | |
# #...##....# | |
# .#..#...#.# | |
# MAP | |
lines = File.readlines('input.txt') | |
lines = lines.map(&:chomp) | |
def run(dx:, dy:, map:) | |
x = 0 | |
y = 0 | |
trees = 0 | |
lx = map[0].length | |
while y < map.length - 1 | |
x += dx | |
y += dy | |
trees += 1 if map[y][x % lx] == '#' | |
end | |
trees | |
end | |
puts run(dx: 3, dy: 1, map: lines) | |
puts [ | |
[1, 1], | |
[3, 1], | |
[5, 1], | |
[7, 1], | |
[1, 2] | |
]. | |
map { |(dx, dy)| run(dx: dx, dy: dy, map: lines) }. | |
inject(&:*) | |
# valids = 0 | |
# Benchmark.bm do |x| | |
# x.report do | |
# valids = lines.count do |line| | |
# PasswordPolicy.from_line(line).valid? | |
# end | |
# end | |
# end | |
# puts valids |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
...#..............#.#....#..#.. | |
...#..#..#..............#..#... | |
....#.#.......#............#... | |
..##.....##.........#........## | |
...#...........#...##.#...#.##. | |
..#.#...#....#.....#........#.. | |
....##.###.....#..#.......#.... | |
.#..##...#.....#......#..#..... | |
............##.#...#.#.....#.#. | |
..........#....#....#.#...#...# | |
..##....#.#.#......#.........#. | |
#.#.........#..............##.. | |
....##.##...................... | |
....##..#...........#.......... | |
..#..#.#........##....#......#. | |
..............#..#....#.....#.. | |
.............#...#.....#...#... | |
.#...........#..........#...#.. | |
.#......#.......#......#....... | |
#..#.............#..#....##.### | |
........#.#...........##.#...#. | |
......#..#.....##......#....... | |
.....#.....#....#.............. | |
#...##.#......#......#...#..... | |
...........................#... | |
...#....................#.....# | |
..#.....#...#.....##.....#..... | |
....................#......#..# | |
.......#.....##......##....#... | |
#........##...#.....##..#...#.. | |
........#..#.#......#..###..#.# | |
##.....#.............#.#....#.. | |
..#.................#....###### | |
.#.#..#.....#.#..........#.#... | |
.........#....#...#............ | |
........#..#.....#............. | |
............#.#.............##. | |
...#....#..#......#............ | |
.##....#.....#...#.#........... | |
..#..............#...........## | |
.....#.#.##...#................ | |
..........#..#.#..........##..# | |
..#....#...#...#.....######.... | |
....#.#..#........#....#.###... | |
.......................#....... | |
..#.....#.##................#.. | |
.....#......#..#.....#........# | |
.#...###.......#.#.........#..# | |
............#.................. | |
..#.........##.........##...... | |
#...........#.#.......###.#.... | |
.#...#.....#.........###.....#. | |
.#............#........#..#.... | |
...##.#......##................ | |
........#...#...#...#.......... | |
.......#.##......##.#.......... | |
....##.......#..#....#....#.... | |
......#.........###........#... | |
#....#....####....##......#.... | |
......................#....#.#. | |
...#.#.#....#.#...#...#......#. | |
......#.....##.#...........###. | |
#........#.........##......#.#. | |
....##.....#.....#..#.......... | |
......#...#...#.........#...##. | |
..#........#..................# | |
.........#..##.#..#..#...#.#..# | |
.....#.....#...#.....###.....## | |
.............#....#...#........ | |
..........#.#.#...#..#...#....# | |
#...............##.......#..... | |
#...#.............#..#...#....# | |
..#...#...##...##...#..#....... | |
..#..#........#.#...........#.. | |
.....#.....#..................# | |
....#....##....###..###...##... | |
..#......###.........##....#.## | |
.......#.##...#.......#..#..... | |
...#.#.#.#.....##..#..#........ | |
................##....#.#...... | |
..#...#...#...#.....##.#...#..# | |
..#..#.....#..##....#....#..... | |
.###...#......#........#.....## | |
##......#..#........#.......... | |
....#...#..#....##..#......#### | |
.#.....##....#..........#...... | |
.#...#....#.........#...#....#. | |
.....#..#.#..#......#..##....#. | |
...#.##...#...#........#......# | |
.#..#...#.#..#.........#...#... | |
#....#......##.....#.......#... | |
..##............##..#.#.#...#.. | |
##.......#.......##............ | |
#......#.##........#...#...#... | |
.#.#.......##.........#..#.#... | |
.............##.#........#..... | |
.#..#...###...#..#............. | |
.....#...#..#....#.......#..... | |
#.#.........#.#.#...#...#.#.... | |
.....#.......#.##.##...#....#.. | |
.#.##..#.....#...#.#.#.#.#..#.. | |
..........#...................# | |
.....#.#.#...##.........#..#..# | |
.#..#....##......#...#......... | |
.##......#......#...#........#. | |
.....##.#......#............#.# | |
.#.....##..#...........##...... | |
.....#......#.......##....#.... | |
..#..##..........#.#..........# | |
#.#.......##..#..##.#....#..... | |
.......#..#.#.......##......#.# | |
....#...##...#..............#.. | |
.....#.........#......#...##... | |
#.........#........##..#.....#. | |
.#.#..#.....##.......#......#.. | |
........#..#....#.....###..#... | |
#.#..#.#..........#............ | |
..#......##..#....#.........#.. | |
#.............................. | |
.......#............#..#..#.#.. | |
.#.....#.#....#..#.##.#........ | |
.......#.###.#........##.#..#.. | |
..............#....#.....##.#.. | |
#..............#....#.###...... | |
.#..#..#...###............#...# | |
.#.##...#....#..#...#...#...... | |
......##..#..#......#..#....#.. | |
.........#.......##............ | |
...........##...#..#....####... | |
.#..................#.......... | |
#...#..#..................#.... | |
..............#.....##.....#... | |
..#.#..#...##..#.....#.....#..# | |
....#....#.#.........#.....#... | |
.#.......#...#....#...#.#..#..# | |
#.........##.....##.......#...# | |
#..#............#....#........# | |
..........##...#......#....#... | |
.......#..##...............#... | |
#............#.#.#.....#....... | |
.#........##...#............... | |
..##....#.....#..#.##.#......#. | |
.#...#.............#...#.....#. | |
...##....#.......#......#.#..#. | |
#......................#..#.##. | |
...#..........#..#.........#... | |
..#......#.......#.#....#...... | |
....#............#...#......#.. | |
.....#..#..##...#...#.........# | |
.....#......#....#....#........ | |
.............#..#..........#... | |
....#..............#.....#.#... | |
....#.................#.#...#.# | |
.........#.#...........###.#.## | |
#...........#..##.#....#.##.#.. | |
#.#.....#...................... | |
##.#.........#....##.#.#..#.#.. | |
#..........#.#.#.#.#..#..##..#. | |
..#...#..###.........#......#.. | |
.....#......#..#.#............# | |
...........#...#.#.#.###....#.. | |
#....#..#.......##.#.......##.. | |
..............#.....##.#....... | |
.#.....#.#..#.........#.#.#..#. | |
..#..#..#..#................#.. | |
...........#..#.#...#.........# | |
.#..#..#...#........#...#.#..#. | |
...#.#..#......#..#............ | |
........#......##.....#....#... | |
#...#......##.#.#.............. | |
.#........................#.... | |
#.#.....#.##.....#..#.#........ | |
#..........##.#.......#....#..# | |
#...#..#..#.....#....#....#.... | |
#...........#..#.#....##.##.... | |
##......#..#........#.......##. | |
#........#..#...#..........#... | |
...#...#......##....#.#........ | |
...##..#..#.##....#...#........ | |
#.#..#....#...#........#....... | |
..........#.......#..........#. | |
......##...#....###...#....#... | |
........#..#.....#......#...... | |
....#.........##...#..##......# | |
....#...........#.#..#.#.#.#..# | |
..#......#..#......#........#.# | |
#..#....#.....#.............#.. | |
............................#.. | |
#...#.#.....#...#....#....#.... | |
........#...#...#...#...#...... | |
.###........#....#.##.....##.#. | |
.........#.....#..........#.... | |
.#.........#....##.#.....#..... | |
#..#....................##.#... | |
..##.#.............#....#.#.... | |
..#.#........#............##.#. | |
#........#...##.....#...#.....# | |
.........#.#..........#....#..# | |
...###.#..#.#......#.#.....#... | |
......#.....#..#...#........#.. | |
.......#...#.....#....#....#..# | |
.#.#........#......##.......#.. | |
#.................###.......... | |
#........#.#..#....#..#........ | |
..##....#.#...##...#...##....#. | |
...#.#......##...#.....#..#.... | |
#..#........#...###....#....... | |
##.#....#..#.#..........#...... | |
....#...###...#.....#........#. | |
..#.#........#....##.#......... | |
......##.##.................##. | |
.#....##...#.#..#.#............ | |
.#...###........#......#....... | |
##..#.#......#..#..#...#....... | |
.......##..#....#........#....# | |
......#..........#............. | |
....##..##..#......#.#......... | |
.....#....................##... | |
...###.....#.....#...#.#.##.#.. | |
....#.#..#.......#..#......##.. | |
.......#.#..#.##.#...#......#.. | |
...#.#....#.#...#..##...#...#.. | |
#.##...#....#..#.............#. | |
...#...#...#.......#..........# | |
.#..#.............#..##.#...... | |
....#.......#..............#.#. | |
..................#..#.....##.# | |
.#...#..#......#..........#...# | |
..#.#.....#..#....#....#####.#. | |
.......###.......#....#....#... | |
......#.#........#...#......... | |
......#..#.#.#....#.#.#....##.. | |
.#...#.#...##.#......#......... | |
#....#..##....#.#.......#....#. | |
..##.#.....#.....#.........#... | |
......#......#....#....#.....#. | |
...##.....#....#......#......#. | |
......#......##............#.#. | |
.##.#.......#....#...#....#.... | |
....#..#..#...##.......#..#.... | |
....#....#...#.#........#..#... | |
....#.....#..........#..#...... | |
....#....#...#.....#..##.....#. | |
##...#..##......#....##..#..#.. | |
.....##.##..............##..... | |
#.#....#.##..#....#...##....... | |
..#.....##.....#.....######...# | |
...#.....#.#.#......#......##.# | |
...........##.............#.... | |
...##......#..#......#...#..... | |
....#.##......#..#....#.#..#... | |
.#..#....#...#..#.....##....... | |
.....#..#.................#..#. | |
................#..#...#......# | |
...##....#.....#..#....##...... | |
....##...............##...#.... | |
......#..........#..##......... | |
.......###.......#.........#..# | |
......................#....#.#. | |
#.#.....#...##............#.... | |
........#......##......#.....#. | |
...#....#....#.#..##.#..#.#.#.. | |
..#.#....#.##...#..#.....#.#... | |
............#....#..#.......#.. | |
#...#...#.#......#...##.....#.# | |
......#....#....#.......#...... | |
....#.......#..........#....#.. | |
........#####........#....#.... | |
......#....##..............#.#. | |
....#....#.......#.......#..... | |
.##.#....##....#............... | |
#.....##........#..#.#...#.#... | |
...#......##....#.............. | |
.#.....#.....#.......##....##.. | |
#....#..........#.#..#......... | |
......##..........##.......#... | |
.##......##.....#.#....#......# | |
....#......................#... | |
.#...........###........#...#.. | |
#.#..#..#..#...##.#....#.#..#.. | |
...##...........#.#..........#. | |
......#.#..#....#....#......... | |
....#....#.#......#.........##. | |
.#..#...#...##....#...#......#. | |
#.#......#...#.#.#...........#. | |
##.....#..........##....##..##. | |
...#.#.....#..##........#...... | |
..#........##........#..#...... | |
.......#...............##..#... | |
.......#.#....#..###........... | |
.............#........#...#.... | |
#.................#......#..#.. | |
...#....#..#..............#...# | |
.............#....##....#..##.. | |
#........#..........##...##...# | |
............#....#.....#.#....# | |
.....#..............##..#...#.. | |
..#....#......###....#.#...##.. | |
....##......#.....#....#....... | |
.....#...............#.....#... | |
.#.....#.....#..............#.. | |
#................#..#.......... | |
.##....#....#.....#............ | |
#.####...#..#..#....#.......... | |
..##........##.....##......#..# | |
......#.....#...##.........##.. | |
....##..#.....#.#.........#...# | |
.....##..#....#....#.#...#..#.. | |
...#............#...........#.. | |
.......#.#..#.#.#..#........#.# | |
....#.#........#.#.#..#...#...# | |
..#....#....#..#......#........ | |
.#...........................#. | |
.#..#....####........##......#. | |
.#.....#..#.#.................# | |
.#..#...........#...#....#...#. | |
......##..#........#..#....#... | |
..#.............#....#........# | |
#.#..........#.##.......#.#..#. | |
..#....#...#...............#... | |
..............#..........#..#.. | |
..#.....#.#.....#...#...#..#... | |
.........#...###.#...#........# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment