You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
13 lines
471 B
Racket
13 lines
471 B
Racket
7 years ago
|
#lang reader "../aoc-lang.rkt"
|
||
7 years ago
|
|
||
7 years ago
|
(provide (rename-out [#%mb #%module-begin]))
|
||
7 years ago
|
(define-macro (#%mb (STARS) (NUMBER) ...)
|
||
7 years ago
|
#'(#%module-begin (captcha-sum 'STARS NUMBER) ...))
|
||
7 years ago
|
|
||
7 years ago
|
(define (captcha-sum stars num)
|
||
|
(define digits (number->digits num))
|
||
|
(define offset (if (eq? stars '★) -1 (quotient (length digits) 2)))
|
||
7 years ago
|
(for/sum ([digit (in-list digits)]
|
||
|
[other-digit (in-list (shift-cycle digits offset))]
|
||
|
#:when (= digit other-digit))
|
||
|
digit))
|