lisp:
CL-USER> (defun common-chars (&rest strings)
(apply
COMMON-CHARS
:
CL-USER> (common-chars "Toby" "Tiny" "Tory" "Tily")
(T NIL NIL T)
:
CL-USER> (defun common-chars2 (&rest strings)
(apply
'list
#'(lambda (&rest chars)
(when (apply
(first chars))) ; return the char instead of T
strings))
COMMON-CHARS2
CL-USER> (common-chars2 "Toby" "Tiny" "Tory" "Tily")
(
:
CL-USER> (format t "~{~@[~A ~]~}" (common-chars2 "Toby" "Tiny" "Tory" "Tily"))
T y
NIL
I admit that this was not an algorithm ... just a way to do it in lisp using existing functionality
If you want to do this manually, as already mentioned, you will compare all the characters in the given index with each other. If all match, save the appropriate character.
source
share