feat: add day 3 solution

main
Brandon Hartshorn 2020-12-12 00:40:44 -06:00
parent 5a2904f1fc
commit 523eebf429
2 changed files with 363 additions and 0 deletions

323
3/input Normal file
View File

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

40
3/solution_3.rkt Normal file
View File

@ -0,0 +1,40 @@
#lang racket/base
(require racket/function)
(require racket/list)
(define width 31)
(define input-file "input")
(define (tree? character)
(equal? #\# character))
(define (get-input-hill file)
(with-input-from-file file
(thunk
(for/list ([line (in-lines)])
(map (lambda (character)
(if (tree? character) 1 0))
(string->list line))))))
(define (count-tree-hits step speed col hill)
(+ (list-ref (first hill) col)
(if (>= speed (length hill))
0
(count-tree-hits step speed
(remainder (+ col step) width)
(list-tail hill speed)))))
(define (sledding step speed hill)
(count-tree-hits step speed step (list-tail hill speed)))
(let ([hill (get-input-hill input-file)])
(*
(sledding 1 1 hill)
(sledding 3 1 hill)
(sledding 5 1 hill)
(sledding 7 1 hill)
(sledding 1 2 hill)
))