Anonymous user
Anagrams: Difference between revisions
cleanup in CL
(added a CL solution, using DRAKMA to retrieve the wordlist) |
(cleanup in CL) |
||
Line 153:
<lang lisp>(defun anagrams (&optional (url "http://www.puzzlers.org/pub/wordlists/unixdict.txt"))
(let ((words (drakma:http-request url :want-stream t))
(wordsets (make-hash-table :test 'equalp)))
▲ ;; populate the wordsets, close words
(do ((word (read-line words nil nil) (read-line words nil nil)))
((null word) (close words))
Line 167 ⟶ 165:
(setf (gethash letters wordsets)
(cons 1 (list word)))))))
;; find and return the biggest
(loop
for pair being each hash-value of wordsets
if (> (car pair) maxcount)
do (setf maxcount (car pair)
maxwordsets (list (cdr pair)))
else if (eql (car pair) maxcount)
do (push (cdr pair) maxwordsets
finally (return (values maxwordsets maxcount)))))</lang>▼
▲ (values maxwordsets maxcount)))</lang>
Evalutating
|