1
0
Fork 0
This commit is contained in:
Jonathan Chan 2020-12-02 21:34:24 -08:00 committed by Jonathan Chan
parent 1830a24fbc
commit 51d5a9006f
3 changed files with 391 additions and 0 deletions

323
input/03.txt Normal file
View File

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

54
src/03.rkt Normal file
View File

@ -0,0 +1,54 @@
#lang racket
(require "../lib.rkt")
(define test
(lists->vectors
(map string->list
'("..##......."
"#...#...#.."
".#....#..#."
"..#.#...#.#"
".#...##..#."
"..#.##....."
".#.#.#....#"
".#........#"
"#.##...#..."
"#...##....#"
".#..#...#.#"))))
(define input (lists->vectors (map string->list (problem-input 3))))
(define (trees grid right down)
(define width (vector-length (vector-ref grid 0)))
(for/sum ([i (range 0 (vector-length grid) down)])
(if (char=? #\#
(vector-ref (vector-ref grid i)
(% (* (/ i down) right) width)))
1 0)))
(define (test-input grid)
(define (print-test right down)
(let ([trees (trees grid right down)])
(printf "Part 2 test (~a right, ~a down): ~a\n"
right down trees)
trees))
(printf "Part 2 test: ~a\n"
(* (print-test 1 1)
(print-test 3 1)
(print-test 5 1)
(print-test 7 1)
(print-test 1 2))))
(define part1
(trees input 3 1))
(define part2
(* (trees input 1 1)
(trees input 3 1)
(trees input 5 1)
(trees input 7 1)
(trees input 1 2)))
(test-input test)
(show-solution part1 part2)

14
template.rkt Normal file
View File

@ -0,0 +1,14 @@
#lang racket
(require "../lib.rkt")
(define (parse in) in)
(define input (parse (problem-input 0)))
(define part1 #f)
(define part2 #f)
(show-solution part1 part2)