From 1e98c88ed5669d2f7ff84ded7ae361c00277724f Mon Sep 17 00:00:00 2001 From: haskal Date: Thu, 3 Dec 2020 00:22:35 -0500 Subject: [PATCH] day 3: triple shork --- 3.rkt | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 3.rkt diff --git a/3.rkt b/3.rkt new file mode 100644 index 0000000..f7c4d22 --- /dev/null +++ b/3.rkt @@ -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"))