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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
aoc-racket/2017/d02/main.rkt

16 lines
582 B
Racket

#lang reader "../aoc-lang.rkt"
7 years ago
(provide (rename-out [#%mb #%module-begin]))
(define-macro (#%mb (STARS) (NUMBER ...) ...)
#'(#%module-begin (checksum 'STARS '((NUMBER ...) ...))))
(define (checksum stars intss)
(define (max-min-diff ints) (- (apply max ints) (apply min ints)))
(define (no-remainder ints)
(for*/first ([duo (in-combinations ints 2)]
[result (in-value (apply / (sort duo >)))]
#:when (integer? result))
result))
(define row-proc (if (eq? stars ') max-min-diff no-remainder))
(apply + (map row-proc intss)))