day 3: triple shork

This commit is contained in:
xenia 2020-12-03 00:22:35 -05:00
parent 7f0b579a01
commit 1e98c88ed5
1 changed files with 35 additions and 0 deletions

35
3.rkt Normal file
View File

@ -0,0 +1,35 @@
#lang curly-fn racket
(require "scripts/aoc.rkt")
;; solution for day 3
;; helper functions here
(define (find input dx dy)
(for/sum ([j (in-range 0 (vector-length input) dy)] [i (in-range 0 +inf.0 dx)])
(define line (vector-ref input j))
(if (~>> (vector-length line) (modulo i) (vector-ref line))
1 0)))
(define (part1 input)
(find input 3 1))
(define (part2 input)
(for/product ([args (in-list '((1 1) (3 1) (5 1) (7 1) (1 2)))])
(apply find input args)))
(module+ main
(define input
(for/vector ([line (in-list (file->lines "inputs/3"))])
(for/vector ([char (in-string line)])
(match char
[#\. #f]
[#\# #t]))))
;; part 1
(answer 3 1 (part1 input))
;; part 2
(answer 3 2 (part2 input))
(displayln "meow"))