Skip to content

Instantly share code, notes, and snippets.

@dvanhorn
Created December 3, 2020 18:55
Show Gist options
  • Save dvanhorn/103f539194fea6d0bf58ff3a46014200 to your computer and use it in GitHub Desktop.
Save dvanhorn/103f539194fea6d0bf58ff3a46014200 to your computer and use it in GitHub Desktop.
Advent of Code, Day 3, Part II
#lang racket
(define in "...")
(define (string-ref-mod xs i)
(string-ref xs (modulo i (string-length xs))))
(define lines (call-with-input-string in port->lines))
(define (c δx δy)
(for/sum ([x (in-range 0 +inf.0 δx)]
[y (in-range 0 +inf.0 δy)]
#:break (>= y (length lines)))
(if (char=? #\# (string-ref-mod (list-ref lines y) x))
1
0)))
(* (c 1 1)
(c 3 1)
(c 5 1)
(c 7 1)
(c 1 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment