http://www.perlmonks.org?node_id=1233621


in reply to Data compression by 50% + : is it possible?

It's too late for me and I may be wrong, but storing the first character and then the deltas (e.g. consecutive character differences) (got the idea from LanX's Re: Data compression by 50% + : is it possible?) achieved ~50% compression using gzip:

# a.pl use strict; #never warnings; my @inp = (); #daraset for (1..100){ my @ani = (); for (my $x=0; $x<90; $x+=10){ my @c; push(@c, int (rand(10)+$x)); push(@c, int (rand(10)+$x)); push(@c, int (rand(10)+$x)); push(@c, int (rand(10)+$x)); @c = sort{$a<=>$b}@c; for (my $i = 1; $i < @c; $i++){ push(@ani, chr(33+$c[$i])) if $c[$i] != $c[$i- +1] && $c[$i] != $c[$i-1]+1 ; } } push @inp, \@ani; } foreach my $abc (@inp){ print $abc->[0]; for(my $x=1;$x<@$abc;$x++){ print ord($abc->[$x])-ord($abc->[$x-1]); } print "\n"; }
perl a.pl > xyz ls -al xyz gzip xyz ls -al xyz.gz