Refactor elisp/anagram/get-char-count
This commit is contained in:
@@ -6,15 +6,16 @@
|
|||||||
|
|
||||||
(provide 'anagram)
|
(provide 'anagram)
|
||||||
|
|
||||||
(defun make-char-count(s)
|
(defun get-char-count(w)
|
||||||
(let ((char-list (mapcar (lambda (char) (string char)) s))
|
"Return an associative list of character counts for W."
|
||||||
(char-counts ()))
|
(let ((char-list (mapcar (lambda (char) (string char)) w))
|
||||||
|
(char-count ()))
|
||||||
;; Build an associative list from the character list.
|
;; Build an associative list from the character list.
|
||||||
(dolist (char char-list char-counts)
|
(dolist (char char-list char-count)
|
||||||
(if (assoc char char-counts)
|
(if (assoc char char-count)
|
||||||
(setcdr (assoc char char-counts)
|
(setcdr (assoc char char-count)
|
||||||
(1+ (cdr (assoc char char-counts))))
|
(1+ (cdr (assoc char char-count))))
|
||||||
(setq char-counts (cons (cons char 1) char-counts))))))
|
(setq char-count (cons (cons char 1) char-count))))))
|
||||||
|
|
||||||
(defun compare-char-counts(char-counts comparison-char-counts)
|
(defun compare-char-counts(char-counts comparison-char-counts)
|
||||||
(let ((are-equal t))
|
(let ((are-equal t))
|
||||||
|
|||||||
Reference in New Issue
Block a user