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/d04/main.rkt

16 lines
537 B
Racket

#lang reader "../aoc-lang.rkt"
(provide (rename-out [#%mb #%module-begin]))
(define-macro (#%mb (STARS) (WORD ...) ...)
#'(#%module-begin
(time (for/sum ([ws (in-list '((WORD ...) ...))]
#:when (no-duplicates? ws #:anagrams? (eq? 'STARS '★★)))
1))))
(define (sort-chars word)
(sort (string->list (symbol->string word)) char<?))
(define (no-duplicates? ws #:anagrams? [anagrams #f])
(let ([ws (if anagrams (map sort-chars ws) ws)])
(= (length ws) (length (remove-duplicates ws)))))