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.
16 lines
518 B
Racket
16 lines
518 B
Racket
7 years ago
|
#lang reader "../aoc-lang.rkt"
|
||
7 years ago
|
|
||
|
(provide (rename-out [#%mb #%module-begin]))
|
||
|
(define-macro (#%mb (STARS) (WORD ...) ...)
|
||
|
#'(#%module-begin
|
||
|
(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)))))
|