Browse Source

Day 3

master
Magic_RB 1 year ago
parent
commit
b977255da6
  1. 323
      day3/input.txt
  2. 25
      day3/solution1.el
  3. 26
      day3/solution2.el

323
day3/input.txt

@ -0,0 +1,323 @@
...#...#..#....#..#...#..##..#.
.#..#.....#.#............###...
.#...###....#.............##..#
...##...##....#.....##..#.##...
.....###.#.###..##.#.##.......#
#...##.....#..........#..#.#.#.
......##.......##..#....#.#....
....#.###.##..#.#..##.##....#.#
.......#.......###.#.#.##.....#
.........#.#....#..........#.#.
.#...##.....##.........#..#....
.##....#.#.#...##......#.......
##.#.#..#....#....#....#...#.#.
##....#.#..##......#....##...#.
....#..#..##..#.###.......#.#..
.....##....###...........#.#.##
#.....##.........#....##......#
........###.#..#....#....#.....
...#.......#.##..#.###......#..
...............#..#....#.##....
..#..###..#.#..#.........##..#.
####..#..####..................
#...####...#.......#.#.#...#...
......###.....#......#..#..#...
#...#.....##.....#.#..##...#.#.
#...........##.......#.........
.#..#.........#.#..##....#.....
........##...#................#
........#.###.#.###.#.#.##..##.
.#....##.....#...##.#..#.#.....
..#..#.....###....##.#....#.#.#
#......##.##...##..#.........#.
#..#..#.....#.....#.........#..
#....#.#...###.........#...#...
.#.#.....##......#.#......#....
..##......##...#.#.#.#.........
..#......#.....##.###.#.#..#...
....#..#.......#..#..#.....#...
.#.#.....#...#..........#......
#.#..#...........#.#.##.#...#.#
..#.#....###...#...#.....#.#...
....##.#.###....####.......#...
.....##....#.......#..#..#....#
...##..#.#.#.#......#......#...
...##...#....#...#......###...#
........#..#.#.....#.###.......
..#..##.#....#.#.........#...#.
.....#.####....#.##.........#..
......#...#...#.....#......###.
.##.....#....#..#.#....#.....#.
...........#...#....##..#...#..
.....#....#.....#...##..#...#.#
.#...#.........#.......#...#..#
...#..#...#........#......#....
..#..#####.#.....#.#....#...#.#
...#.......#.#....#...##..#..#.
####..#.#.###.#.#..............
.##........#...#.#....#..#.....
..#..............#.#..##...#.##
.###.#.....#.#.....##.#......##
....###.....#...#...#.#..#.....
....###.#.##.......#....#...#..
#..#...#......##..#.....#.#...#
....#.#.........#..............
#.##.##...#..#.#.#.....#...#.##
#...#...#......#...........##..
#.#.#......#............#.#....
.#.#..######...#.#.........#.##
..#.#..#...#......#............
....#.....#......##..#.....#...
.##............#....##..#......
.#.#.#...#.##.............###.#
#.#...#...#.....#....#.#.#.....
........#..#......##.##.#.....#
.....#.....#.#####...#....#....
.#...#......#.........#.#......
...#...#..##.....##....#..#....
....#....##..#.........#.......
..#........##..#.#........#....
...#...##...........#...#....#.
.....##.........#..#....#..#.#.
#..#....##..#...##.....#..##.#.
..#.#.#.#...#...#.....#.#....#.
.......#.###...#.#.......#.#...
....#..#..#.###.#.....###..#.#.
.#..##......#..#..#....#.####..
..##...........#...#.........#.
......#..#...#..........#......
....#..........#......##...#...
....#..#.##........#.#...##.#..
#.##......#........##.#...#...#
#..#....#.....###........##....
...........##.....##..#....#.##
..#....#..#..#......#.#.....#..
#....#.##....#.....##.......#..
.#.....#.#..............#.##..#
.#..#..#...#...#....#.#.....#..
...###...##.#...#..#........#..
#...#.##.#.....#.#....#..#.....
#.....###.#.......#.#..#.#..##.
....#..#..##.......###.#...#...
.#...####...............#.....#
.#.##.#.....#.....#.#......##.#
#...........#.##....###.##....#
...............#..........#....
.....#..#.##.###.#.............
...##.............#.....#.#..#.
....#.#...#.#..#..#..#....#....
..#.......#..........#...#...#.
...............#.#.#...###....#
....#...#.##....#..##....#.....
........#.#.##.........##.##.##
#.....###.......#.#....#..#..##
.#..#...#......#.#..##.......#.
#.....#.#........#.##..#..#....
.###..##.#.......#......###....
.#...###.....#.....#....###...#
........##.##......#.#....#...#
.#....#..#.........#..##...##..
.......#.......##.#..#..##.....
#..##..##......#.#......#.##...
..#..###..#...#....#..#...#....
#.............#.####.........##
..#..................#...#..#..
..#......#........##.......#.#.
.#.#.#.#..###.....#....#.#.....
...#.##.###.......#....#.......
................##...#.....#...
..#.###.#...#.####....#..#..#..
..#....###....##..#.#.........#
.#..#.#.....#........#....##...
.....#..#......#..#..##.#.#....
.#..#.........##....##......#..
.....#.#...#...#.#...#.#...#.#.
..#..#...#...#...##.#..###.....
..#..##......#..##.#...##......
.......#..##....##.#......#..#.
..#......#.#.....#.##....##....
..#....#......#......##........
....##.#.#....#.......#.##.....
#.....#...###....#....#...#....
............#.#..#...#...#..#..
..##.............##....#.......
.#.......#.##.#......#....##...
...##............#....#..#...#.
.##.####.....#.#..###.#....#.##
....##.#........#..#...#.......
...#...###.##...........##..#..
..##..##....#...#..#..........#
..#.........#.#...##..........#
.......##....#.#...##.....#..#.
.............#.....#.#.......#.
#.......#..##..##...##.#.......
..............#.....#.#..#...##
........##..#.....#...#...#.#..
###.#.................#........
...#........#...#.#######..#..#
...#.##...##.#.#..######...#...
#.......#..#....#..#.##.....#..
#..#....##....#.##.......#....#
#...#..#.#.#...#..#.##..#......
....#..##....#..#.#...........#
.##..#.#.............###.......
#....##......#..#..#.....###...
..#..........#...###.#.........
.####......#....#......#.#....#
..#....#.#.#......#....#.......
.....#.....#....#....#####....#
.##..........#...#.###....#....
....##.....##......#...#.#.....
.#...#...#..#.#.#...#####......
...#.##..####.##.##.......##...
............#.......#..........
.#..##.#..#####........#..#...#
#......##..##..##.........##...
....#....#.............#.#....#
###..#.....#.....#.#...#..#.###
#...#.......##......#....#.#.#.
...#......#..#...#....#...###.#
....#....##.......#....#......#
............#......##.##.....#.
...#.........#......#....##..##
.....##....##...#..###...#..#..
.......##.#..........#.##.##...
....##...........#.#..#..#.##.#
#...#..##.##.#....#....#.#.....
...##.#.....#..#..#..###....##.
#.##.#..#..#.#.............#...
..#.#.............###.....#....
...#..#....#..#.....#.#..#..#..
...#.....##.#...........#..##.#
.........#.#.##..#..#.#...#....
...#..##..#...#...###.##.#..#..
.#..##...##......##..##........
......##....##.#.##.#.#........
...#..................#.....#..
.##................#.#..#..###.
.##.##.....#................#..
.....#.#..........#...#..#.#..#
.............#......#..#.#..#..
...#...##..#........#....#.....
#......#........##.##...##.....
##..#..##....#...#............#
..##..##.##....##..##........#.
...#....#.#.#.#....#.#...##....
....#...##..##.#.##...#..#...#.
#..#....##.#.....#.......#...##
##.#....#.............#..#.....
.##..#..#.#.....#.......#.#..#.
.......#..#...##...#...###..#..
..........#...#.#..##.....#...#
..#....#...........#####....#..
#....#..#.......##.............
.........##..#####.......##....
#..#..........#.....###...#..#.
.#.#.#..#...#.......##...#####.
.....#....#.###...#.......#....
#.#.....##...###....###....#...
.#.....#..#.#.#........#...#...
.##.#.#.#......#....###....#...
.#..##..####......###......#...
......#.#.#.#.#...#...####.##..
.#........##..#.....#....#....#
.....###......##..#....#.......
#.#.##...#.#......###..........
........#.#...#..#......#....#.
..##...##.........#.......#.#..
..#.##....#...##.....#.###.....
.........#..#.#....#....#.#.##.
#.........#......#..#.......#..
...#...##.......#.........#....
............#......#...........
##.....#.....#.#...#.....#.....
..#.#...#..#...#.#...........#.
#.#.#..#..#...##.#...#.#.....#.
.#..###.#..##.#.....#.....#....
##....##....#.......##..##.....
.#..#...........###..........#.
.#..#..#..........###..#.......
#..###......#............##...#
#......#........#..#..#..#.#...
.......#.###...#.##............
.##....#.......#.#...##.....#.#
....#..#.#.......#.#...........
##....#.###.#....#.#..##.#....#
..#..#..#....#...#........##...
...#...##....#..#.#...#..#.....
......#..#......#....#.......#.
#.#..............#...###...#..#
...#....#..#..........#.#...#..
#.....##..##.....#........#....
.#...##..#.#..............#....
##.#....#..##...#..#.####.#..#.
.....#.......#.#.#.#..#.....###
...#.##....#.#........##.......
#...#.#...#.#..###..##.##...#.#
###..............#.#.###.......
...###..#.#..#....##...###.#...
......##...........#...#..#...#
.#..#.........##.......#..#...#
.#.......###......##...#...#...
.#......##...#........#.......#
.#..#.....#.........#.#........
#...#.#.....#...#..##.........#
......##.#......##.#..##.#.....
...............#.#..#....#....#
#....#..#..#..#.#.....##...##..
#.#......#.###......#..#...####
.#.#..#...#...#.#..#.##.##.#.#.
.....#.#...###...#.#.....##....
...#..#.#..........##.#....#.#.
...#..#.#.##.....###.##.#....#.
..........#..###......#..#.#...
###.....#..###..#...#..###.#...
..#..#.....##.#.#..###.......#.
....#....##........##..........
.......#..........#...#......#.
.#........#.#.#.#.#.......#....
.#..#.......##..##....#.#...#..
.#.#.#.......#..#..............
#.#....#.#...#.#.#.....#.#...##
.....#..........##..#.......#..
.##......#.#....#.#.......#....
..#.##....#.##.#...#...........
...##......##..##.............#
..........##.#.#..#..........#.
.##....#..#..#.#....##.#...#.#.
...........#....#.....#.#..#...
.#.....#....##..#.........#....
.....#.....#...#....#...#.###.#
..#....#....#.....#...#......#.
.....##..#.............#...#...
........#..#.......#.#.......#.
#...###..#.##.#...###...##..##.
....##..#.......#...#.#........
.#...#.#.##....####........#..#
.#...#.#.####.##.#.............
#..##...#....#...#.#.#.#.##..#.
.#.......#........#.....###....
#.#.....#....#..#....#..#....#.
...#..#...#.....#.........##...
.#....#......###...#....#.#.#..
#.#........#......#...#....##..
.....#..#......#..#..#......#..
.#.....#..#.##.#.#.#...#......#
##........#..#.#..#...#.####...
..........##....#.#..#.#....#..
#.##..#..#....#..#....##..#.#.#
..#......#.......#...##..#.....
##...#.........#......#......#.
.#.....................#..#.##.
.#.......#........#.#.#..##.#..
..#..........#........#..##.#..
.#...#...#.........##.#.#.#....
....#....#.###.#....###....#.##
....##......##........##.#.##..
....#.#......#.##.#...#.##.....
....#....#..#.#..###.#.#.......
....#......#..#.#.......#..##..
.....#..#.#.##.##..##.....#.#..
...#....................##.....
#.....#...##...#.#.............
..#.#...#.#.#.....##..#....#...

25
day3/solution1.el

@ -0,0 +1,25 @@
#!/usr/bin/env -s emacs --script
(load (expand-file-name "../lib" default-directory))
(setq-local lines (read-lines "input.txt"))
(defun build-map (txt-map)
(cl-loop for line in txt-map
collect (cl-loop for tile across line
collect (if (string-equal (char-to-string tile) "#") t nil))))
(setq-local x-moves (list 3))
(setq-local y-moves (list 1))
(setq-local x-pos 0)
(setq-local y-pos 0)
(setq-local map (build-map lines))
(message "Encountered %s trees" (cl-loop for i from 0
for x = (nth (% i (length x-moves)) x-moves)
for y = (nth (% i (length y-moves)) y-moves)
do (setq-local x-pos (% (+ x-pos x) (length (nth 0 map)))) (setq-local y-pos (+ y-pos y))
while (< y-pos (length map))
sum (if (nth x-pos (nth y-pos map)) 1 0)))

26
day3/solution2.el

@ -0,0 +1,26 @@
#!/usr/bin/env -s emacs --script
(load (expand-file-name "../lib" default-directory))
(setq-local lines (read-lines "input.txt"))
(defun build-map (txt-map)
(cl-loop for line in txt-map
collect (cl-loop for tile across line
collect (if (string-equal (char-to-string tile) "#") t nil))))
(setq-local map (build-map lines))
(defun find-trees-at-slope (x-slope y-slope)
(setq-local x-pos 0)
(setq-local y-pos 0)
(cl-loop
do (setq-local x-pos (% (+ x-pos x-slope) (length (nth 0 map)))) (setq-local y-pos (+ y-pos y-slope))
while (< y-pos (length map))
sum (if (nth x-pos (nth y-pos map)) 1 0)))
(message "%d" (* (find-trees-at-slope 1 1)
(find-trees-at-slope 3 1)
(find-trees-at-slope 5 1)
(find-trees-at-slope 7 1)
(find-trees-at-slope 1 2)))
Loading…
Cancel
Save