Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

function to split a string into a list of characters

4 views
Skip to first unread message

Robert L.

unread,
Mar 16, 2018, 5:31:06 PM3/16/18
to
Eric Smith wrote:

> ; (rm1 "abc" 0) ==> "bc" (rm1 "tea" 1) ==> "ta"
> (defun rm1 (seq which)
> (remove-if #'true seq :start which :end (1+ which)))
>
> ; (consword #\a "bc") ==> "abc"
> (defun consword (char word)
> (concatenate 'string (string char) word))
>
> ; (anagrams "ah") ==> ("ah" "ha")
> (defun anagrams (word)
> (if (= (length word) 1) (list word)
> (loop as x across word
> as i upfrom 0
> as subword = (rm1 word i)
> nconc (loop as y in (anagrams subword)
> collect (consword x y)))))

> (map list->string (permutations (string->list "jug")))
'("jug" "ujg" "jgu" "gju" "ugj" "guj")

--
[Amazon bans history book after it received 300 5-star reviews.]
http://archive.org/details/nolies
0 new messages