; npr sunday puzzle
(define (take n xs)
(let loop ((n n) (xs xs) (ys '()))
(if (or (zero? n) (null? xs))
(reverse ys)
(loop (- n 1) (cdr xs)
(cons (car xs) ys)))))
(define (fold-right op base xs)
(if (null? xs) base
(op (car xs) (fold-right op base (cdr xs)))))
(define (set-cons x xs)
(if (member x xs) xs
(cons x xs)))
(define (abcdef? word)
(equal? (string->list "abcdef")
(take 6 (sort char<?
(fold-right set-cons (list)
(string->list word))))))
(with-input-from-file "dictionary"
(lambda ()
(let loop ((word (read-line)))
(when (not (eof-object? word))
(when (= 8 (string-length word))
(when (abcdef? word)
(display word) (newline)))))))