Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

99problems: 9, 11, 13

6 views
Skip to first unread message

Gabriele Renzi

unread,
Jan 7, 2007, 1:58:28 PM1/7/07
to perl6...@perl.org
Hi people,

I implemented 13 from scratch because I didn't know it was already
solved, in this way

sub encode_direct(*@array is copy) returns Str {
my ($packed, $count);
while @array {
if @array[0] eq @array[1] {
$count++;
}
else {
$packed ~=( $count ?? ($count+1) ~ @array[0] !! @array[0] );
$count=0;
}
@array.shift;
}
return $packed;
}
is encode_direct(<>),'', 'We should be able to encode_direct an empty list';
is encode_direct(<a>), 'a', '.. or a one-element list';
is encode_direct(<a a>), '2a', '.. or a n-ary list with always same
element';
is encode_direct(<a a a a b c c a a d e e e e>),
'4ab2c2ad4e',
'.. or a generic list';

I think it's cleaner, shall I commit?

And in general, I could use a $first variable to keep the value in
@array[0], but I don't think it adds in readability, terseness and (if
the interpreter is Smart Enough(TM) ) not even in efficiency, what would
be the right thing to do?

Thanks again for any comment.

Gabriele Renzi

unread,
Jan 9, 2007, 10:12:20 AM1/9/07
to perl6...@perl.org
Ovid ha scritto:

> I definitely think your solution is cleaner, but I'd be more inclined
> to see multiple solutions to problems rather than clearing out previous
> work. Not only does this follow the spirit of TIMTOWTDI, but it also
> allows the tests to cover a wider range of behavior.

of course two solutions are better than one, I don't know why I didn't
think of this :)

> It's not really my call, though. Commit bits are there for a reason :)

true :)

0 new messages