SP-Forth
REQUIRE /STRING lib/include/string.f
REQUIRE PLACE ~mak/place.f
REQUIRE { ~ac/lib/locals.f
REQUIRE StringReplace2 ~nn\lib\string.f
REQUIRE printf<[ ~ilya\Lib\win\System\printf.f
REQUIRE list-all ~ygrek/lib/list/all.f \ all words for cons pair lists
list ALSO!
REQUIRE CASE-INS lib/ext/caseins.f \ Case-insensitive.
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.
HenHanna 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.
SP-Forth
Let's sort by the penultimate character.
: get-ch ( cadr n -- chr ) drop 11 + c@ ;
mylist :noname count get-ch swap count get-ch swap < ; sort
HenHanna 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.
SP-Forth
REQUIRE /STRING lib/include/string.f
REQUIRE PLACE ~mak/place.f
REQUIRE { ~ac/lib/locals.f
REQUIRE StringReplace2 ~nn\lib\string.f
REQUIRE printf<[ ~ilya\Lib\win\System\printf.f
REQUIRE list-all ~ygrek/lib/list/all.f \ all words for cons pair lists
list ALSO!
REQUIRE CASE-INS lib/ext/caseins.f \ Case-insensitive.
: get-bin-digits ( u n -- ...) 0 do dup 1 and swap 2 / loop drop ;
: str-0-term ( adr) count + 0 swap c! ;
create form-str 257 allot
0 value cnt
0 value power
: dotty { adr len -- }
\ Doesn't terminate output string with 0-byte.
form-str adr len s" ." s" %d" StringReplace2
form-str str-0-term
len - to cnt drop
1 cnt 0 do 2 * loop to power
power 0 do
printf<[ i cnt get-bin-digits form-str count ]>
type cr
loop
;
s" apple.bun.c" dotty
apple0bun0c
apple0bun1c
apple1bun0c
apple1bun1c
s" apple.bun.c.d" dotty
apple0bun0c0d
apple0bun0c1d
apple0bun1c0d
apple0bun1c1d
apple1bun0c0d
apple1bun0c1d
apple1bun1c0d
apple1bun1c1d
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 504 |
Nodes: | 16 (2 / 14) |
Uptime: | 25:07:01 |
Calls: | 9,907 |
Calls today: | 3 |
Files: | 13,799 |
Messages: | 6,345,634 |