Jump to content

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, and close wordsstream
(maxcount 0)
(maxwordsets '()))
;; 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 wordsetwordsets
(loop forwith pairmaxcount being= each0 hash-valuewith ofmaxwordsets wordsets= '()
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>
;; return the biggest wordset and its size
(values maxwordsets maxcount)))</lang>
 
Evalutating
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.