[ create a new paste ] login | about

Project: programmingpraxis
Link: http://programmingpraxis.codepad.org/m7yajoBT    [ raw code | fork ]

programmingpraxis - Scheme, pasted on Feb 15:
; 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)))))))


Create a new paste based on this one


Comments: