Advertisement
Guest User

Unscrambling words

a guest
Feb 11th, 2012
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.47 KB | None | 0 0
  1. (defun read-lines (filename)
  2.   (with-open-file (in filename)
  3.     (loop as line = (read-line in nil) while line collect line)))
  4.  
  5. (defun anagram-p (w1 w2)
  6.   (equal (sort (subseq  w1 0) #'char<) (sort (subseq w2 0) #'char<)))
  7.  
  8. (defun unscramble (word wordlist)
  9.   (loop for i in wordlist if (anagram-p word i) return i))
  10.  
  11. (let ((wordlist (read-lines "wordlist"))
  12.       (words (read-lines "words")))
  13.   (dolist (i words)
  14.     (format t "~a -> ~a~%" i (unscramble i wordlist))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement