Deutsch English Français Italiano |
<20240518140005.921@kylheku.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder9.news.weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Kaz Kylheku <643-408-1753@kylheku.com> Newsgroups: comp.lang.lisp Subject: Re: Given string 'a.bc.' -- replace each dot(.) with 0 or 1 Date: Sat, 18 May 2024 21:06:16 -0000 (UTC) Organization: A noiseless patient Spider Lines: 39 Message-ID: <20240518140005.921@kylheku.com> References: <v29p14$2mr5l$2@dont-email.me> Injection-Date: Sat, 18 May 2024 23:06:17 +0200 (CEST) Injection-Info: dont-email.me; posting-host="e91c99aee57c8d742a6a3dcafbf58b79"; logging-data="3121327"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19KqGnOCaOwucsTppAHFNir7ThKOkxnoxU=" User-Agent: slrn/pre1.0.4-9 (Linux) Cancel-Lock: sha1:Iiz6xh5YzsNzcJoB2yucTgLCww8= Bytes: 2082 On 2024-05-18, HenHanna <HenHanna@devnull.tb> wrote: > > How can i write this function simply? (in Common Lisp) > > -- Given a string 'a.bc.' -- replace each dot(.) with 0 or 1. > > -- So the value is a list of 4 strings: > ('a0bc0' 'a0bc1' 'a1bc0' 'a1bc1') > > -- The order is not important. > If the string has 3 dots, the value is a list of length 8. > > If the program is going to be simpler, > pls use, e.g. (a $ b c $) rather than 'a.bc.' TXR Lisp: (defun bindots (str) (let* ((s (copy str)) (ixs (where (op eql #\.) s)) (n (len ixs))) (collect-each ((digs (rperm '(#\0 #\1) n))) (set [s ixs] digs) (copy s)))) 1> (bindots "abc") ("abc") 2> (bindots "a.bc") ("a0bc" "a1bc") 3> (bindots "a.b.c") ("a0b0c" "a0b1c" "a1b0c" "a1b1c") 4> (bindots "a.b.cd.e") ("a0b0cd0e" "a0b0cd1e" "a0b1cd0e" "a0b1cd1e" "a1b0cd0e" "a1b0cd1e" "a1b1cd0e" "a1b1cd1e") -- TXR Programming Language: http://nongnu.org/txr Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal Mastodon: @Kazinator@mstdn.ca