From fbc975b7d7551368935a6ffaa7f5ea0fbe1927f7 Mon Sep 17 00:00:00 2001 From: dcw Date: Mon, 26 Aug 2019 00:07:58 +0100 Subject: improved comments in LZW.pm, fixed trivial thing in encdecode.. --- challenge-022/duncan-c-white/perl5/LZW.pm | 11 +++++++++++ challenge-022/duncan-c-white/perl5/encdecode.pl | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/challenge-022/duncan-c-white/perl5/LZW.pm b/challenge-022/duncan-c-white/perl5/LZW.pm index ced6381511..5dac1ca36e 100644 --- a/challenge-022/duncan-c-white/perl5/LZW.pm +++ b/challenge-022/duncan-c-white/perl5/LZW.pm @@ -11,6 +11,17 @@ # quite clear is what initial alphabet both encoding and decoding should # use? but let's have a go anyway, hopefully building an encoder will # start to clarify most things? +# +# Update: the encoding was very straight forward, but I struggled for +# several hours to get my head around the decoding - especially the +# special case described in the wikipedia page where the dictionary +# doesn't contain the entry. The description was NOT CLEAR ENOUGH +# in that case (and giving an example text where the special case +# applied would have helped a lot, eg TOTOTOT was the shortest I found) +# +# Eventually, with time running out, I checked some Rosetta code +# implementations, discovered what pseudo-code the description +# really mapped onto, and adapted it to fit my code.. # use strict; diff --git a/challenge-022/duncan-c-white/perl5/encdecode.pl b/challenge-022/duncan-c-white/perl5/encdecode.pl index b8bc99a774..24e7916c4a 100755 --- a/challenge-022/duncan-c-white/perl5/encdecode.pl +++ b/challenge-022/duncan-c-white/perl5/encdecode.pl @@ -26,8 +26,9 @@ lzw_setdebug( 0 ); die "Usage: encdecode STRING\n" unless @ARGV==1; my $text = shift; +$text .= '#' unless substr($text,length($text)-1) eq '#'; + my $binstr = lzw_encode( $text ); -#$text .= '#'; print "\ntext: $text\n" if 0; #print " encodes to: $binstr\n"; my $text2 = lzw_decode( $binstr ); -- cgit