aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordcw <d.white@imperial.ac.uk>2019-08-26 00:07:58 +0100
committerdcw <d.white@imperial.ac.uk>2019-08-26 00:07:58 +0100
commitfbc975b7d7551368935a6ffaa7f5ea0fbe1927f7 (patch)
tree0fd6df0ca5f5ce4152cb9c38eed9e1c26d826a75
parentf5039f944a330188ffa46849baf25d4ece9c9a66 (diff)
downloadperlweeklychallenge-club-fbc975b7d7551368935a6ffaa7f5ea0fbe1927f7.tar.gz
perlweeklychallenge-club-fbc975b7d7551368935a6ffaa7f5ea0fbe1927f7.tar.bz2
perlweeklychallenge-club-fbc975b7d7551368935a6ffaa7f5ea0fbe1927f7.zip
improved comments in LZW.pm, fixed trivial thing in encdecode..
-rw-r--r--challenge-022/duncan-c-white/perl5/LZW.pm11
-rwxr-xr-xchallenge-022/duncan-c-white/perl5/encdecode.pl3
2 files changed, 13 insertions, 1 deletions
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 );