_$ (Decompress "ab2c3")
"ababcababcababc"
_$ (Decompress "ab4c3d2")
"ababababcababababcababababcdababababcababababcababababcd"
I assume repeat "A" 2 times then 3 times :|That has been my assumption. And I have assumed a non-empty string.
Design query :
- assume the string is not empty and contains printable characters.
- Assume the first element is not numeric.
:|
Design query :Your assumption is correct:
does a string "A23" mean repeat "A" 23 times or repeat "A" 2 times then 3 times ??
I assume repeat "A" 2 times then 3 times :|
...each numeral digit means ...
Another interesting issue: What if the input string does not end in a digit?Really? Please explain?
< .. >
Another interesting issue: What if the input string does not end in a digit?
_$ (Decompress "")
""
_$ (Decompress "6")
""
_$ (Decompress "3a2b")
"aab"
_$ (Decompress "a2b")
"aab"
< ..>
No, first element could be numeric as well ... does it make any difference in the result?]
< ..>
- Assume string only contains characters of 0-9 and a-z
If you really want to you can do those too, but it's not a big issue. Actually the way I've written mine means everything except for 0-9 will be possible in the result.
- Assume string only contains characters of 0-9 and a-z
So, no A-Z ?
Another interesting issue: What if the input string does not end in a digit?Really? Please explain?
Code: [Select]_$ (Decompress "a2b")
"aab"
Revised code to account for empty string input.Awesome! Very close to mine, most notable difference is mine works with lists instead of strings.
(f "ab2c3" "")
"ababcababcababc"
(f "ab4c3d2" "")
"ababababcababababcababababcdababababcababababcababababcd"
(f "a23" "")
"aaaaaa"
_$ (Decompress "a23")
"aaaaaa"
That's what I get for being noob this might be correct depending on if this is correctCode: [Select]_$ (Decompress "a23")
"aaaaaa"
Does (Decompress "a23") = "aaaaaa" or "aaa"?
Ahhh, I see you've changed the 'specs' to clarify ...
Ahhh, I see you've changed the 'specs' to clarify ...
That's how it works in real life. The specs have a way of evolving to accommodate the unforeseen. It helps to have several perspectives. 8)
My argument has always been that we need to learn how to ask questions as much as we need to learn to solve problems.
My argument has always been that we need to learn how to ask questions as much as we need to learn to solve problems.+1 I agree with you on this, unfortunately I didn't foresee the possibilities. In my mind some of them didn't matter - seeing as they didn't apply to the results (only to the implementation).
hi Jeff H!Either I got lucky or you screwed up.
We have written the same code :coolsmiley:
hi Jeff H!
We have written the same code :coolsmiley:
(DEFUN <RECURSIVE-FUNCTION> (<PARAM1> ... <PARAMN>)
(COND (<TERMINATING-CONDITION1> <RESULT1>)
.
.
(<TERMINATING-CONDITIONN> <RESULTN>)
(<RECURSIVE-CONDITION1> <RECURSIVE-CALL1>)
.
.
(<RECURSIVE-CONDITIONM> <RECURSIVE-CALLM>)))
I do not have much experience with Lisp but can most problems be solved in Lisp withYes "most" ... though unlike some other Lisps (e.g. Scheme) AutoLisp doesn't have tail-call-elimination, thus recursion would cause stack overflows if the call stack becomes too deep. So generally be careful when you're processing something like a list longer than around 10k to 20k.
DESIGN QUERY.From the original challenge I would conclude that a zero in the strings means ignore all previous characters.
Is this design correct ??
a Zero in the string only ignores the characters preceding it since the previous digit value. ??Code - Auto/Visual Lisp: [Select]
(equal (eea "") "") => T
(equal (eea "0") "") => T
(equal (eea "a2") "aa") => T
(equal (eea "ab2c3") "ababcababcababc") => T
(equal (eea "1ab2c3") "ababcababcababc") => T
(equal (eea "ab12c3") "ababcababcababc") => T
(equal (eea "ab2c30") "") => T
(equal (eea "ab0c3") "ccc") => T
< .. > The compression algorithm created a string where each numeral digit means the uncompressed string preceding it is repeated that many times.
give me 2 choices and I have a 90% chance of being incorrect :-)
"ab2c30"
(((("ab" * 2) + "c") * 3) * 0) = ""
give me 2 choices and I have a 90% chance of being incorrect :-)
red and blue pill? :-D
(decompress "a") => "" ; as "a0"
or
(decompress "a") => "a" ; as "a1"
@ Lee:
(decompress "ab4c3d22") => ...
as correctly?Code: [Select](decompress "a") => "" ; as "a0"
or
(decompress "a") => "a" ; as "a1"
(defun decompress (l / a b c)
(if (setq b (vl-member-if
(function (lambda (x) (setq a (cons x a)) (< 47 x 58)))
(vl-string->list l)
)
)
(decompress
(vl-list->string
(append (reverse (repeat (- (car b) 48) (setq c (append c (cdr a))))) (cdr b))
)
)
l
)
)