aoc2020/3.rkt

36 lines
792 B
Racket

#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"))