Skip to content

Commit

Permalink
meh solution
Browse files Browse the repository at this point in the history
  • Loading branch information
rmNULL committed Dec 3, 2020
1 parent d866d45 commit 647b45c
Show file tree
Hide file tree
Showing 3 changed files with 357 additions and 0 deletions.
23 changes: 23 additions & 0 deletions 2020/3/3.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

def count_trees(xd, yd=1)
in_f = ARGV.first ? File.open(ARGV.first) : ARGF
n_trees = in_f.readlines.drop(1).reduce([xd, 1, 0]) do |(xpos, ypos, n_trees), line|
if (ypos % yd).zero?
x_repeat = line.strip.length
tree_found = line.strip[xpos % x_repeat] == '#'
[xpos + xd, ypos + 1, n_trees + (tree_found ? 1 : 0)]
else
[xpos, ypos + 1, n_trees]
end
end[2]
in_f.rewind
n_trees
end

# 1
puts(count_trees(3))

# 2
puts([[1], [3], [5], [7], [1, 2]].reduce(1) { |r, n| count_trees(*n) * r })
323 changes: 323 additions & 0 deletions 2020/3/input
Original file line number Diff line number Diff line change
@@ -0,0 +1,323 @@
.........#..##.##..............
#...#.#..#.....................
.#...#..#...................#..
........##..#...#..............
.#.#.....#..#..##......#.......
....#..#...#..##........#..##..
...#....##........#.......#.#..
....#................#...###..#
...#...#.#..#....#.......####.#
.....#...#..........#...#..#.#.
....#..#............#.#.#.#..#.
..#....#.###..#............#...
.....#.............#.#.........
.#.##............##.........#..
...##...#..#....#.##..#.....#..
..............#.#.........#.##.
...........#.....##....##......
.......#............#...#......
............#.#....#....#..#..#
....#................####......
...#.........................##
..........#........#.#.........
....#.#....#...........#......#
..#.#..##......##..##..#..#.#..
...#.....##......#.#.#.........
.........#.#....#...#.#.#......
.......#.......###.#.......#...
..#............##..#.......#...
...#....#......#...#...#...#...
......#..#.#.....##......#.....
...........##...##...#....#.##.
#.##..#.....##..#.#............
.#.#.....##......#.##........#.
..#...#...#...#..........#...##
...##.........................#
.....#......#.....##....#.....#
..#........#...................
#......#..#.#..#..#.#..#...#...
...............#..........#....
.....#...........#......#....#.
........#..#...............#...
.........#...#.......#.#..#...#
..#..#......#.##..........#....
.#...#....#.....#.............#
.##.....#.........#......#..#..
........#..##.......#......#...
.......#.....###......#..#.....
.......#.#.......#.............
...#................##.#.......
..##..#...#.#...#.#..#.#.#.##..
.......#.#............#...#....
#...#.....#......#..........##.
.#.......#......#.......#.#.#..
.#.##.#.#...........#..........
.......#.....#....#.#.##......#
.###..#...#.............##.....
......#......#.................
##...#.#...##...#.#.....#....#.
#.............#....##...#....#.
#.#...#....#........#.###..##..
......#.........#......#.#.#.#.
..#.#.#.....#........#..#...#..
#.##....#.#......#...........#.
.#.#.####.........#..#.##....##
......##...............#......#
.......#.........#........#.#..
....#....#..#.##.........#..#..
.#..........#.##....#.#..#.....
#..#.#............#..#....#.#.#
..................#..#.........
##..##.#....#.................#
..................#........#..#
.....#.........#.......##......
.....................#.#..#...#
.....#.........#..........#.#..
...#.#..#..#.#.#.......#.......
.....#.....#.#.........#.....##
.............##....#....##.#...
.#......#........##..#...###...
........#.......##.##.#......#.
..#....................#.##..#.
......#.......#..#....##.#.....
...#....#.......##...#.......#.
.#.#..#.#..........##..........
....#.......##...........#.....
###....#.......#..#...#.....##.
...#......#.........#..#.#..#.#
#.........#..##.#..............
.#.....#..##.#..#..###.....##.#
..........#..#....##.......#...
.#..#.#...#...##.#..#.##.#.....
#....#...#........#......##....
..#.####....#.#........#....#..
#......#............#.#........
...#..#.......##...........#...
.........#..#.#..#.###.#...#..#
..#....##.......#.............#
............#..#......#........
........#......#..............#
..#.#.#...........#............
...........#......##.#.#.......
.#..........#...........#..#...
.....#...#..#.........##...#...
.......#....##....#.#.........#
..#.#......#.......#...##.#....
.....#..........#........#.....
#.......#.......#............#.
..##.#.....#.##.#.#.#..#.......
..#...#.......#.###............
.#...#..#....#...#...#..#....##
.....#.....#...................
.......................#......#
......#...##.........#...#..#..
.....#..#.....#..............#.
.#.##..#..#....................
....#..#...#....#.............#
..###..#...#......#.....#......
..#......###....#.....#.....###
...#.##..#...#.....#........#..
.#.#...........##....#...#.##..
.......#...##......#..#..#.....
#.............#..#...##.#..#..#
..........#......#.......#.....
...............#.#.#....#...#..
#.......#.#..#.....#........#..
.#.#.#.......#..#.........##...
......#.....#.#....#...........
..#.....##.#........##.#......#
...###...#..#.........#........
....#...................#..#...
.##........#...................
....#..#...........#.#.........
.....#.......#...#....#.#......
.........#...#.......#.#...#...
.......#.#..#....#....#.......#
..#.............#..............
.#...#..#.#.#..#............#..
...#.##.##..#..#...........##..
...........#...#..#.#........#.
....#...#.....#...#.#....#...#.
.......#.#...##..#.............
.......................#....#..
..#..#.....#...........#....#..
.#..#...#.##........##....#....
#.....##.#.#.......#.....#...#.
.#....#.......................#
#..##..###...#.........#.......
..##...#...#..........#....#...
......#..##......##.#.........#
................#........#..#..
.....#.#..#.....#.......#..#...
..#..#.....#.......#..#..#...#.
.#....#...#...#......##.....#..
....#........#...#......##....#
..#..........##......#......#..
#.#.....#.....#.......#........
...#...#......#....##.#..#...##
...#....#...#.#...........##...
#....##...#...#....#...........
...#.#..#...#..............##..
#..#..........##.#.#.....#.....
..#...#.........#.#..........#.
....#.....#..........#.........
........................#......
.#.....#.#...###...#....#......
....##....#....#..#.##........#
..#........#.........#.......#.
.....#.#......#...#...#........
........#..#.....#....###....#.
...........#..#.#....#.#....##.
.......#.....##.#............#.
...............#........##.##..
.............#...##......#...#.
#...##.#.......#......###.....#
..........#...#........#..#....
....#....................#...#.
.#......#...#.......#....#.#...
....#.......................#..
#...#...#...#.##....##.........
..........#.#...##.#...#.......
..#...............#....#..#...#
#..#..#...#..#.........#...#...
.....#..#..........#.##.#..##..
........#......##.....#........
.#....#.#.........#...#..#.#...
....#..............##..........
#...............#..............
..###.........#....##.........#
.........#.#....##........#...#
....#.#..#......#...#..........
...#.#.....#....#..#....#.#..#.
............#..#.....#...##....
...........#....#.#.#...#......
#...............#....###.......
.........#.....##.#..#..#......
...#...##...###...............#
.#......#.#.#.................#
.........##..#............#....
..#..#.....#.....#.#...........
.#......##............#.#....#.
.#.##..##.##..#.........#.....#
...##.##......##.##......#.....
##.....#.#...#...#...#..#......
....................#......#...
.....#.................#...###.
...........#..#.........#.#....
...#........#..#........#....#.
#................#......###...#
.............##.#.....#.#......
...#...#.##..#........##.......
#..#.##...#....#.#.............
.#.........#.#..#...........#..
....#...#.....#.#..........#...
.#.#....###.......##.....#.##..
.##....##......#......#.#....#.
..#...#.#........#...#..##.....
..............###..........##..
#....#..##.....#.....#.....#...
...#...#....................#..
.#....#.#.....#.#..#..##.......
#...##..###......#.............
..........#.#....##.#........##
..#..#.....#...#....#.#.#......
#.....#........#..##.#.........
....#.....#..........##......#.
......#..#.....#........#.....#
.....#..#....#...........#.##..
.#....................#....#..#
........#..#...........#.......
#....#.#.......#........#.#..#.
........#.....#...#............
..#........#........#....#...#.
.....##.......#..#..........#..
......#.#......###...#....##..#
.#..#.............#.#..........
#.....##.#.#.#.#.#.....#.....#.
.#..#.....#.......#.#.....#....
###....##...#.#...#..#......###
.#................#.....#.##...
....##....#.#........###.#.#...
#.#....#........#.....#.......#
..........#..........#.##...#..
....#....#..##......#..#.......
.....#..........#.##...........
##......#.#......#.##..........
##..........##.......##........
..#.....#....#.##..#..#..#.....
......###...#...........#...###
#..#.............##............
...#.###.....#..#.........#.#..
......#...............#...#.#..
.....#...##.#...#.....#.#..#...
..#..#.#....#.#................
...............##.....#........
......#.#.....#...#.........#..
........#..#...#.#...#......#..
#...........#.......#...##...#.
........#.#...#..##..#.#...#...
..#....#...#......#..........##
..#..............##...##.#.....
...#....#..#....##.........#.#.
.#.#....#..........#.......#...
...##....#.#....#....#.#...#...
..............#..##........#..#
..........#.#...##......#..#.#.
#...##..#......................
.......#........##.#.#.#.......
.........##..#.#.......####....
..#.............#..#........##.
##..#..#...#....#.....#...#..#.
..#.#...#.#.....#..............
..#....#....#..##...#.#........
##.....#..#...#................
#....#.....................#...
..............###.....#.#.#....
..#......##.#....#.#...##......
#...#.#......#...#.#......#....
....#...................##.#...
.........##......#.....#.####..
##..#........#.....#......##..#
...#..#...#...#.............#..
#..#..#.#......###...#.........
.......#.#..#........#....##..#
............#..##.....#.#.#....
#..#.....#.....#....##........#
......#..........##............
.....#...#...........#.........
...........#....#...#....#.#...
....#.........##.##.......#....
......#....#...........#.##...#
.##.#.#..##...#.....##.#...#...
.......#.#....#...#...#....#...
.#...##.#.#.....#..#....#......
.#....###..#.......#......#...#
..#.#.........#.........#.....#
.......#.#.##..#.#.......##..#.
.##............#.........#....#
.#...##.###..#........##.#..#..
..#........#.#.....##..##.#....
...........#...........#.....#.
.#...######..##...#.....#......
.#.##.#.......#......#......#..
.#.....#.....#........#........
...#..#...#.##...#...........#.
.......#.....#.......#.........
............#...###...........#
...#.......#.......##....#..#..
##.......#....#....####........
.......#.#......#..........#..#
#.....##..#..#.....#....#...#..
#............#........##.......
.#.#...#.............#..##.....
.#....#..#.#......#.##.......##
...................##...##..###
..#.....#...#................#.
..#...#....#...#.#.#...#.....#.
.....#............#....#...#..#
.#.....#....#..#......#.#.....#
............#.#.....####.##....
....#......###....#...#....#...
#.....#..#.....#..#...#.......#
..#.#...#....#....##..#...##...
.##..#..#..##....##...#........
11 changes: 11 additions & 0 deletions 2020/3/sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
..##.......
#...#...#..
.#....#..#.
..#.#...#.#
.#...##..#.
..#.##.....
.#.#.#....#
.#........#
#.##...#...
#...##....#
.#..#...#.#

0 comments on commit 647b45c

Please sign in to comment.