Last active
April 27, 2019 05:25
-
-
Save dmitrym0/d37abd39e41a64e8a3037f94e81cc0c0 to your computer and use it in GitHub Desktop.
emacs lisp sandbox. see if all characters in a string are unque
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun are-any-chars-duplicated (char-array &optional top-char) | |
"Takes in a list of characters and returns true if there's a dupe char. returns false if all chars are unique" | |
(message "top char: %s and array is" top-char) | |
(princ char-array) | |
(cond ((null char-array) false) | |
((null top-char) (are-any-chars-duplicated (cdr char-array) (car char-array))) | |
((equal (length char-array) 1) | |
(progn | |
(message "1 comparing %s %s" top-char (car char-array)) | |
(equal top-char (car char-array)) | |
) | |
) | |
(t | |
(progn | |
(message "2 comparing %s %s" top-char (car char-array)) | |
(or (equal top-char (car char-array)) | |
(or (are-any-chars-duplicated (cdr char-array) top-char) | |
(are-any-chars-duplicated (cdr char-array) (car char-array))) | |
) | |
) | |
) | |
) | |
) | |
(message "result %s" (are-any-chars-duplicated '("a" "b" "z" "z"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment