Hi people,

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

sub encode_direct([EMAIL PROTECTED] 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.

Reply via email to