On 5/18/2024, HenHanna wrote:
-- 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.
Gauche Scheme:
(use srfi-13) ;; string-count
(use util.combinations) ;; cartesian-product
(define (dot s)
(let ((b (cartesian-product (make-list (string-count s #\.) '(0 1))))
(fs (regexp-replace-all "[.]" s "~d")))
(map (cut apply format fs <>) b)))
(dot "a.b.c") ===> ("a0b0c" "a0b1c" "a1b0c" "a1b1c")
(dot "a.b") ===> ("a0b" "a1b")
(dot "ab.") ===> ("ab0" "ab1")
(dot ".ab") ===> ("0ab" "1ab")
(dot "ab") ===> ("ab")
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 76 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 55:38:45 |
| Calls: | 1,265 |
| Calls today: | 1 |
| Files: | 1,362 |
| D/L today: |
3 files (2,684K bytes) |
| Messages: | 285,684 |