Perhaps, he really didn't mean to compress a list of ONE element. :-)
(compress '( 1 1 1 0 1 0 0 0 0 1 1 ) ) => ( (3 1) 0 1 (4 0) 1)
Actually manages to be two cons cells less (if I count correctly).
Maybe that's run-length( run-line) encoding...
This does smack of a homework problem so I'll pass on offering up a
solution.... although I'd imagine that (= (first lst) (first (rest lst)))
--
Lyman S. Taylor "Because no matter where you go,
(ly...@cc.gatech.edu) there you are."
Buckaroo Banzai
This looks like a homework problem.
Either that, or you need to explain why you think this will be an
Lyman S. Taylor wrote in message <6hme4b$6...@pravda.cc.gatech.edu>...
>In article <sfwbttt...@world.std.com>,
>Kent M Pitman <pit...@world.std.com> wrote:
>>mil...@usc.edu (Robert Miller) writes:
>...
>>> >(compress '(1110100001))
>>> ((3 1) 0 1 (4 0) 1)
>....
>>improvement in storage. The output representation looks to be using
>>more storage than the input, so the choice of the name COMPRESS is
>>funny unless this is an academic exercise.
>
> Lyman S. Taylor wrote in message <6hme4b$6...@pravda.cc.gatech.edu>...
>
> > Perhaps, he really didn't mean to compress a list of ONE element. :-)
> >
> > (compress '( 1 1 1 0 1 0 0 0 0 1 1 ) ) => ( (3 1) 0 1 (4 0) 1)
> >
> > Actually manages to be two cons cells less (if I count correctly).
>
> Yeah, it does look like homework... This was in the 1st for 2nd chapter of
> ANSI Common Lisp by Paul Graham. I don't recall if he gave it as an example
> or a as a problem. I think as an example.
Ah, I see now.
And here I thought he was looking for someone to tell him about
(multiple-value-bind (quotient remainder) (truncate n 2) ...)
or (ash n -1) or (ldb (byte 1 0) n) so he could save all the
consing it would take to do it the "easy way" with FORMAT's ~B
and SUBSEQ and CHAR.