Refactor elisp/anagram/anagrams-for
Reformat. Use push macro over low-level list-manipulation.
This commit is contained in:
@@ -29,18 +29,16 @@ CHAR-COUNT and COMPARISON-CHAR-COUNT should be alists in (character . count) for
|
|||||||
(setq are-equal nil))
|
(setq are-equal nil))
|
||||||
(setq are-equal nil)))))
|
(setq are-equal nil)))))
|
||||||
|
|
||||||
(defun anagrams-for(word anagrams)
|
(defun anagrams-for (word anagrams)
|
||||||
"Return all elements of ANAGRAMS which are anagrams for WORD.
|
"Return all elements of ANAGRAMS which are anagrams for WORD.
|
||||||
Case insensitive."
|
Case insensitive."
|
||||||
(let ((candidates ())
|
(let ((candidates ())
|
||||||
(word-char-count (get-char-count (downcase word))))
|
(word-char-count (get-char-count (downcase word))))
|
||||||
(dolist (candidate anagrams candidates)
|
(dolist (candidate anagrams candidates)
|
||||||
(if (and
|
(when (and (not (string-equal word candidate))
|
||||||
(not (string-equal word candidate))
|
(= (length word) (length candidate))
|
||||||
(equal (length word) (length candidate))
|
|
||||||
(equal-char-count word-char-count (get-char-count (downcase candidate))))
|
(equal-char-count word-char-count (get-char-count (downcase candidate))))
|
||||||
(if (> (length candidates) 0)
|
(push candidate candidates)))
|
||||||
(add-to-list 'candidates candidate t)
|
(reverse candidates)))
|
||||||
(setq candidates (cons candidate nil)))))))
|
|
||||||
|
|
||||||
;;; anagram.el ends here
|
;;; anagram.el ends here
|
||||||
|
|||||||
Reference in New Issue
Block a user