Author Topic: =={ Challenge }== Decompress String  (Read 11410 times)

0 Members and 1 Guest are viewing this topic.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: =={ Challenge }== Decompress String
« Reply #30 on: August 29, 2014, 10:09:15 AM »
@ ElpanovEvgeniy:
(f "ab4c3d0" "") => "ababababcababababcababababcd0"

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: =={ Challenge }== Decompress String
« Reply #31 on: August 29, 2014, 10:17:40 AM »

Roy, yes, a few of these routines will fail if they contain a zero.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: =={ Challenge }== Decompress String
« Reply #32 on: August 29, 2014, 10:36:38 AM »
@ Lee:
(decompress "ab4c3d22") => ...

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: =={ Challenge }== Decompress String
« Reply #33 on: August 29, 2014, 10:51:26 AM »
Just for the fun of it  ...

Code - Auto/Visual Lisp: [Select]
  1. ;;;------------------------------------------------------------------
  2. ;;;
  3. ;;; Spit the Dummy if 'testStatement evaluates to nil
  4. ;;; argument must be quoted
  5. ;;; kwb 20020715
  6.  
  7. ;;;   (setq var 0)
  8. ;;;   (KDUB:assert 'var "Symbol 'VAR' has no value assigned.")
  9. ;;;   (KDUB:assert '(not(zerop var)) "Symbol 'VAR' evaluates to 0 ... this is illegal ... go to jail")
  10. ;;;   (KDUB:assert '(> var 0) nil)
  11. ;;;   (KDUB:assert '(< var 1) nil)
  12. (defun kdub:assert (teststatement message)
  13.   (if (not (eval teststatement))
  14.     (progn (kdub:display-message
  15.              " **** Assertion Failure"
  16.              (if message
  17.                message
  18.                (list (vl-prin1-to-string teststatement) " ==>> nil/null")
  19.              )
  20.            )
  21.            ;; decide what to do here later ?
  22.            (if kglobal:debug_on
  23.              (princ "  ")
  24.              (exit)
  25.            )
  26.     )
  27.   )
  28.   (princ)
  29. )
  30. ;;;------------------------------------------------------------------
  31. ;;;
  32. ;;; (KDUB:display_formatted_message prefix mess )
  33. ;;; kwb 20020715
  34. ;|
  35. prefix : String or nil
  36. mess   : atom or list comprising STRing, INT, REAL,
  37.         SYMbol, ENAME, VLA-OBJECT, FILEid etc
  38. |;
  39. ;;;
  40. ;;; Print a formatted message to the command line
  41. ;;; (kdub:display-message "Ooops" "DUH")
  42. ;;; (kdub:display-message "Ooops" '( (> 1 2)))
  43.  
  44. (defun kdub:display-message (prefix mess)
  45.           (list "\n"
  46.                 (if (= (type prefix) 'str)
  47.                   prefix
  48.                   "; **** ERROR"
  49.                 )
  50.                 ": "
  51.           )
  52.   )
  53.   (if (vl-consp mess)
  54.     (mapcar 'princ mess)
  55.     (princ mess)
  56.   )
  57.   (princ)
  58. )
  59.  
  60. ;;;------------------------------------------------------------------
  61. ;;;
  62. ;;; Force closure for Dummy-Spit situation.
  63. ;;; Prints the error message and exits
  64. ;;; Forcing an error to be handled by the error handler.
  65. (defun kdub:dummyspit (mess)
  66.   (kdub:display-message nil mess)
  67.   (princ "  ")
  68.   (exit)                                ; let the current error handler clean up  
  69. )
  70.  
  71.  
  72. ;;;------------------------------------------------------------------
  73.  
  74.  
  75.  

Code - Auto/Visual Lisp: [Select]
  1. (kdub:assert '(equal (irneb1_decompress "") "") nil)
  2. (kdub:assert '(equal (irneb1_decompress "0") "") nil)
  3. (kdub:assert '(equal (irneb1_decompress "a2") "aa") nil)
  4. (kdub:assert '(equal (irneb1_decompress "ab2c3") "ababcababcababc") nil)
  5. (kdub:assert '(equal (irneb1_decompress "1ab2c3") "ababcababcababc") nil)
  6. (kdub:assert '(equal (irneb1_decompress "ab12c3") "ababcababcababc") nil)
  7. (kdub:assert '(equal (irneb1_decompress "ab2c30") "") nil) ;;<<== result revised
  8.  

**** Assertion Failure: (EQUAL (IRNEB1_DECOMPRESS "ab2c30") "ababcababcababc") ==>> nil/null

Revise test suite to remove complete current result when digit 0 encountered
« Last Edit: August 30, 2014, 05:12:53 AM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: =={ Challenge }== Decompress String
« Reply #34 on: August 29, 2014, 11:06:24 AM »
DESIGN QUERY.

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]
  1. (kdub:assert '(equal (irneb1_decompress "ab0c3") "ccc") nil)
  2. ;; (kdub:assert '(equal (irneb1_decompress "ab1c0d2") "abdabd") nil)
  3.  (kdub:assert '(equal (irneb1_decompress "ab1c0d2") "dd") nil) ;<<== result revised
  4.  


Revise test suite to remove complete current result when digit 0 encountered
« Last Edit: August 30, 2014, 05:11:26 AM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: =={ Challenge }== Decompress String
« Reply #35 on: August 29, 2014, 11:12:48 AM »
DESIGN QUERY.

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]
  1. (kdub:assert '(equal (irneb1_decompress "ab0c3") "ccc") nil)
  2. (kdub:assert '(equal (irneb1_decompress "ab1c0d2") "abdabd") nil)
  3.  

From the original challenge I would conclude that a zero in the strings means ignore all previous characters.
So:
(irneb1_decompress "ab1c0d2") => "dd"

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: =={ Challenge }== Decompress String
« Reply #36 on: August 29, 2014, 11:14:53 AM »
That's why I'm asking Roy ... People are certain to treat the condition differently, and have different expectations.

This is why having a testing suite is critical.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: =={ Challenge }== Decompress String
« Reply #37 on: August 29, 2014, 11:33:41 AM »
maybe:
Code - Auto/Visual Lisp: [Select]
  1. (decompress "ab2c30") => ""

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: =={ Challenge }== Decompress String
« Reply #38 on: August 29, 2014, 11:45:49 AM »
Code - Auto/Visual Lisp: [Select]
  1. (defun eea1 (s)
  2.   (defun f+ (s i a) (repeat (atoi i) (setq a (strcat s a))) a)
  3.   (defun f (s i)
  4.     (cond ((= s "") s)
  5.           ((wcmatch s "*#") (f+ (f (substr s 1 (1- i)) (1- i)) (substr s i) ""))
  6.           ((strcat (f (substr s 1 (1- i)) (1- i)) (substr s i)))
  7.     )
  8.   )
  9.   (f s (strlen s))
  10. )
Code: [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

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: =={ Challenge }== Decompress String
« Reply #39 on: August 29, 2014, 12:05:14 PM »
I'm not sure Evgeniy,
With a zero in the string ..

Quote
< .. > The compression algorithm created a string where each numeral digit means the uncompressed string preceding it is repeated that many times.

could be read that the result string is repeated zero times in this instance ie not repeated.

I really hate the word assume ..
give me 2 choices and I have a 90% chance of being incorrect :-)


kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: =={ Challenge }== Decompress String
« Reply #40 on: August 29, 2014, 12:08:40 PM »
"ab2c30"
(((("ab" * 2) + "c") * 3) * 0) = ""


ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: =={ Challenge }== Decompress String
« Reply #41 on: August 29, 2014, 12:10:20 PM »
give me 2 choices and I have a 90% chance of being incorrect :-)

red and blue pill?  :-D

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: =={ Challenge }== Decompress String
« Reply #42 on: August 29, 2014, 12:11:49 PM »
"ab2c30"
(((("ab" * 2) + "c") * 3) * 0) = ""


Yes, that would be the rational way to consider it.

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: =={ Challenge }== Decompress String
« Reply #43 on: August 29, 2014, 12:14:29 PM »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Lee Mac

  • Seagull
  • Posts: 12892
  • London, England
Re: =={ Challenge }== Decompress String
« Reply #44 on: August 29, 2014, 12:20:07 PM »
Another:
Code - Auto/Visual Lisp: [Select]
  1. (defun LM:decompress2 ( s / f )
  2.     (defun f ( l a / b c )
  3.         (if (setq l (vl-member-if '(lambda ( x ) (setq c (cons x c)) (< 47 x 58)) l))
  4.             (f (cdr l) (progn (setq a (append (cdr c) a)) (repeat (- (car l) 48) (setq b (append a b)))))
  5.             (vl-list->string (reverse a))
  6.         )
  7.     )
  8.     (f (vl-string->list s) nil)
  9. )
« Last Edit: August 29, 2014, 12:32:21 PM by Lee Mac »