adventofcode

https://adventofcode.com/
Log | Files | Refs

commit 62e176e760dc45302031470b9ed7be61e17c6db0
parent 5b9a99f85f1e606e1db6ff7dfbd99e0951511cf8
Author: mpizzzle <m@michaelpercival.xyz>
Date:   Thu,  3 Dec 2020 11:57:11 +0000

day 3 complete.

Diffstat:
A2020/files/3.txt | 323+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A2020/puzzle_3.scm | 20++++++++++++++++++++
2 files changed, 343 insertions(+), 0 deletions(-)

diff --git a/2020/files/3.txt b/2020/files/3.txt @@ -0,0 +1,323 @@ +...............#...#..#...#.... +...#....##.....##...######..#.. +....#.....#.##..#...#..#....... +...#..........#.#....#......#.. +....#.#...#.#.......#......##.# +....#.#..........#.....#.##.... +##...#.#.##......#......#.#.#.. +#.#.#........#....#..#.#....... +..#...##..#..#.......#....###.. +.#.#..........#...#........#..# +.#..#......#....#.#...#...#.#.# +..#.........#..##.....#.#.##.#. +.#......#...#....#.....#......# +........#..##..##.........#..#. +.....#....###..#....##........# +.###...#..##..#.##......##...## +.#...#...#..#.#..#...##.....#.. +.......#....#....#.#...#....... +.##.......#.##...#.#...#..#.... +#.#...#......#....#.......#.... +..###...............####...#.#. +.##.#....#......#..#...#.#..#.# +.............#.#.#......##..... +#....#.#.#........#....##...#.. +...##....##...##..#...#........ +..##......#...#......#...###... +...#...##......##.#.#..#....... +#......#..#...#.#..#......#..## +.#..#..#........##....##....... +.#...........###.###.##...#.... +............#.#...........#.#.. +#...#........#...#...#..#.#.#.# +...#.......#.#.#..#.#.......... +......#..#..#....##..##..##.... +........##...#......#..#.#..... +..#.#.......#......#........... +#.#.....#......##..........#.#. +#.....###.#...#...#..#....#...# +.##.#...#............##.....#.. +###....#.#.....#.......##...... +##.......##.....#..#...#..##.## +....#.##............###...#..## +.###..#...##.#..#..##..#....... +.##.##..####.....#.........#... +....####..#...#....#.#...#..... +..##....#..#......#...........# +..........#......#..##.......#. +.................#.#.#........# +#.......##.#...##.......##.##.. +.#................#.#.....##..# +......#..#............##.#..... +...##............#.....#.....#. +##.###.#.......#....#.........# +......#.....#.#.#.#......#..... +......#.##......#......##...... +..#....#...#..#.....#..#....#.# +.#.##.##.....#.......#.......#. +...#..#.#......##....##..#..... +.#.....#......##...#..#.#....#. +..#......#....#..#..###.#.#.... +.....#........#.#...#..#.#..... +....#.#.......#...##.....####.. +#..#..##...#...........#...#..# +.#..#...#.....#.....#.#.....#.# +..##..###.....#...#.#.#.......# +#..##.##......###..#......###.. +#..#...#.......#....#.#...#.#.# +...........###..#...#..##....#. +.....#...........###.......#... +##......#.......#......##.#..#. +#.................#........#... +#.#.............#......#...#..# +......#.#....#....#....#....#.# +..#...#....#..#....#....#..#... +#....#......#..#...#..#....#.#. +..#.....#..#...#...#.......#... +.#........###..##.#..#......... +.....##.#.....#..###..#........ +...#...#.###....######......#.. +.###.#..#.....#.....#..#...#... +##..#.#......#.........#...#..# +###...##..###.......#..##.#.#.# +.#...................#..#...##. +.#...#...###...#.......#......# +....#.....##....#...##.#...#.## +..#....#......#...#..###....... +.........#..........##........# +...#.........##..#....#..###... +......#.##....#.#........#.#.## +....#..#...#.............#....# +#..#.....#.#.....#....#........ +....#..#...####.#.###..#....... +.....#....#....#..#..#.#.....#. +#..##....#.....#.#............. +.##...#..#.......#...##.###.... +##......#...##....#......##.... +#......#.#......#.#..#......#.. +.#...#......#............###..# +.#..#.#.....#.#.....#..#....#.. +.#............#...#..#..#...##. +...#...#....#.#.#....#....#.... +........#......###.#....##.##.# +......#.#..................##.. +..#..#........#..##..........## +.#...#.#....#####.#.#..#....... +.....#..#.#..#.....#.#........# +#.#..#..#.#..........#..#..#... +.##........#.#.......#........# +.....#....#..##...#......##.... +....#.##.##...##.#.........#.#. +...#...#..#.#.......#.......#.. +.................##..#......... +..##.##....#...#.##.......#..#. +....#...........#.....###....## +.#..................#.......... +....#.##....#......##.#..#.##.# +#......#..#.#....##...####...#. +#.....#.#.##...........#.##...# +.......#...##..#.........##.... +.#...#..........##......#..#.#. +#...#.#......#.....#........#.. +........#.....#.......##......# +.#..#...........#...#..#..#.... +......#.##......##.#......#..## +......#....#..#................ +##.#.......#......#..#....##.## +..#...###..#.......#...#.#....# +.....#...#.........#.....#..#.# +..#.....#.........#..#...#.#... +.#.........##..#.#...#.....##.. +..........#.#.#...#....#....#.. +....#.###.#..#..#..#.#........# +..#...##...##.#.#.....#.#..##.. +.#..#......#.####..#.......#..# +##.......#.....#.#.#..#...##..# +.##......##...##.........#..#.. +..#.##..#......#......#..#..#.. +..#..#.##..#........#....#.#... +##.####...##.#..##.........#..# +.#.......#.#..#.....#.##....... +........#.........#...........# +..#...#.####.....##.##.#....#.# +.....#..##.#..###.##.#.#...#... +#..##..##....#...#....#...#.... +.###.#....#..#.......#......### +.#....##.....#.#........#...#.# +#.#.#..#..#...#....#..#.....#.. +....##...#.##..#............#.. +##......###...#...#...#....#... +#.#...#.#..#..##.##..##..#....# +.#...#.#....#..##.#..##..#..... +.............#..#..#.#.....#... +#........#..........#....###... +..#..#......#...#........#..... +.#..#.............#.........#.. +#.....#....##..#..#.#.#..#..... +...#......#.........#.#....##.# +..#.......##....###..#......... +.#.......#......#.............. +.#...##.....##...###.#....#.#.. +......#....#.........#.......#. +##.......#..##....###.#.....##. +.....#......####.....#......#.. +....#....#..###....#.....##...# +...#...#.#........#.....#..#.## +#..#....#.#...###...##.....##.. +#.....##...#.#............#.... +##....#.......#.#.#....#.#.###. +#........#...#...####.#....#.#. +.##.#......#........#..#.....#. +...##.#.......#...#.#.##..#...# +......#.........##..#....#..... +.#......#...........#......#... +......#.#.#.#..#.#....#....#..# +##.................##...#.#.... +........#.........#..#..#...### +.#........#........#....#..#... +....###.##.##......#.#...#....# +#......#.#..............#...... +.......#..#....#..##.........#. +#............#....#............ +#...#.#.........##..###...##... +.#....#.#.#.....#..#..##....... +.............##.#.#.......#..#. +#...#..##.#..###.....##..#..... +...#.#.....#...#......##.#..#.. +#..........#.##.#...#...#.#...# +...#.#...#.........#.#..#.#..#. +#....#.................#....... +..#..#.#.#..#.#..##...#.#...... +..#....#.#.#...#.....#...#..... +#...#.###......#.......#..#..#. +#.#.##.##..............#.#.#..# +#..........#.#.........#.###... +...........#.......#.#..#...... +....#.#..#....#....#....##..... +#..#...##########.........#.#.. +..#.............##........#.#.. +#.#.##......#...#.#....##..##.. +..##..#.#.#....#......#.#..#.#. +.#.#...#................#...... +#...#...#.....##.#...#.......#. +.....##.......#...#......#.##.. +....#.##..........#.#.##....##. +...........##........#.#.#.#... +..#...........###.#....#..#.... +..#.#...#...#.#........#.....#. +.##......##.....#........#..... +....#.......#....#...#.##...#.. +.#.....##.....#...##........... +#....#.##.##...#...###.#####... +..#.#......#.#.......#....#..#. +..........#...#...........#.... +.........#..#...#...#......#.## +.#...#.#...#.###.##..#........# +#....#.....#.......##....#..... +#.....#..#.....#...##.......#.. +#.#.#.#.............#.....#...# +...#.....#.....#............... +..##.###.#.#........#.........# +...##..#.##..#....#.#...#.#.... +...##...#...##.#.........#.#..# +.###......#....#.........#.#... +###.#.#...#.......#...#.....#.# +...#.#.......#.....####........ +......#..#.....###.#....#..#... +..####...#...#..#......#...#... +#..............##....#......##. +..##..###...##..#.#.........#.. +#..#.#...#.......#.........##.. +..##....#......#...#..##....... +..#.#..#..###.....#.....#...### +.#..#.##.....##.#.#.#........#. +..#.#.........#................ +..#...........#.#...##.#...#..# +.....#........#..#.....#....#.. +#.#....#...........##.....#..## +##.......#.....#.....#.#......# +.##............####.#........## +....##.#.....#......#....#...#. +.#.#...##.#..##..#..........#.. +..........................#.... +##..##..#..#.#....#.....#...... +...#.#........#.#.##.#.....#..# +#..#....#...#..#...#........#.# +#.......#####...#..#..#.#...... +#.##....#......#......#..###... +..#.......#...........#.....##. +#...#....#..#......##...#...... +...##.#..##........#..###...... +##.#...........#.............## +#.....#..#.....#.....#......... +.#..........#..#......###...... +...#...#..##.......#...#...#.#. +..####......#.....#..#.#......# +....#..#.....#.#............... +.#.......#....#.....#..##....#. +.....#.........#..........##... +#...........#..#.....#........# +............#..##...#...#.#.... +##.............####...#.....#.. +.....#......#....##.#.....##... +...........#.....#.#..#.#...... +.#.#......#....#.............## +##...#.#.......##........#..... +#..#.....#.#.......####...#..#. +....#.#...#....#.###..#..#.#... +.....#.#..#......#.##.#####.#.. +.....#....##..........#......#. +#.......#........##.......##... +#...#..#..##.#....#...#...#.... +...#..##..#...#..........#..... +#..#....###.....#......##...... +...###......#.....#....#....... +#.#...#.#..###.####.......#.#.# +...#......#.#..##..#.....#..... +#.#............#.....##.#...... +#..#......##...##..#...#.#..### +#.....#...#..#..#....#..###.... +####..###....#..##....#..#..... +..##.#.....#.......##....#.#.#. +##..#.#.......#.#...##.#..#.#.. +..#.#.#.##.#.#.#...........#... +...#.##.....#....#..#.#..#..... +...#..#.........#..........#..# +#...#..#.....#.#.#............. +##.#....##.##...#...#..#..#..#. +....####..##..##.#..#...##..... +##.....##.#.#...#.#.......###.. +#..#.#....#......#.......##...# +#.#...............#..#..#...... +.....##...##..#........#......# +.#..#............##......#....# +......#.#..#..##.#......#.....# +..#.#.............#...#......## +....#.#..#..#...##...#..##..... +#.#.............#...#.#..#....# +#..#..#.##....#....#...#....... +....#..#..........#.....##...#. +..#####.......#...#..........#. +....#......##.......#..##.#.#.# +#...#.#.....#....#....##....... +..##.#.#..#.#...#.....##.....#. +#.#..#....#............#..#.#.. +...#.##..##..#.#...###......#.# +......##.......#....#......###. +....#..##.......#..#.#....#..#. +#............#..........##..#.# +..#.....#..#.#..##..#....##.#.. +.....#.....#....##.#.#......#.# +...####.......###..#...#.#....# +.#.##.....##.....##..#..#...... +...#..###..##.................. +##..##.....#.#..#..#.#........# +.#.#........##.........#....#.. +........#......###....#...#.... +......#...........#...........# +.#...###...#.........#.#...#..# +.....#..........#......##....#. +.#.#...#........##.......#.#... +.....##.....##....#...#...#..#. +..#.....................##...## +#..#.#......##...##..#......#.. diff --git a/2020/puzzle_3.scm b/2020/puzzle_3.scm @@ -0,0 +1,20 @@ +(define (check-slice slice x) + (if (char=? (string-ref slice (modulo x (string-length slice))) ##) 1 0)) + +(define (count-trees tree-map x x-offset y y-offset) + (if (not (null? tree-map)) + (+ (if (= (modulo y y-offset) 0) + (+ (check-slice (car tree-map) x)) 0) + (count-trees (cdr tree-map) (if (= (modulo y y-offset) 0) (+ x x-offset) x) x-offset (+ y 1) y-offset)) + 0)) + +(load "read_lines.scm") +(define input (read-lines "files/3.txt" (lambda (x) x))) + +(display (count-trees input 0 3 0 1)) (newline) + +(display (* (count-trees input 0 1 0 1) + (count-trees input 0 3 0 1) + (count-trees input 0 5 0 1) + (count-trees input 0 7 0 1) + (count-trees input 0 1 0 2))) (newline)