From 366b5e801e4ded0a9a75c093b16ee6fcd0b614a2 Mon Sep 17 00:00:00 2001 From: James Smith Date: Sat, 28 May 2022 01:01:56 +0100 Subject: Update README.md --- challenge-166/james-smith/README.md | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/challenge-166/james-smith/README.md b/challenge-166/james-smith/README.md index 23c0dda58b..a73165d2cb 100644 --- a/challenge-166/james-smith/README.md +++ b/challenge-166/james-smith/README.md @@ -326,26 +326,24 @@ sub k_diff { I started with a "simple" compact version of the code and then came discussions with Eliza on the Perl Programmers Facebook group and things -slowly got smaller. A few bytes at a time to the 354 byte: +slowly got smaller. A few bytes at a time to the 272 byte: ```perl -sub k{my($l,$F,%d,%u,$T,$H)=0;(@_=split'/'),push@{$d{$_[0]}},-d?"$_[1]/":$_[1] -for<*/*>;$u{$_}++for map{@{$d{$_}}}my@p=sort keys%d;$l;$lkeys%{$u{$l}}?sprintf$b, +map{$u{$l}{$_}?$l:''}@p:()}sort@_),$a} ``` -**or** if we "allow" return characters inside strings - this is 351 bytes of +**or** if we "allow" return characters inside strings - this is 270 bytes of perly goodness... ```perl -sub x{my($l,$F,%d,%u,$T,$H)=0;(@_=split'/'),push@{$d{$_[0]}},-d?"$_[1]/":$_[1] -for<*/*>;$u{$_}++for map{@{$d{$_}}}my@p=sort keys%d;$l;$lkeys%{$u{$l}}?sprintf$b,map{$u{$l}{$_}?$l:''}@p:()}sort@_ +),$a} ``` **Notes** @@ -364,11 +362,11 @@ For ultimate compactness we can remove the function overhead off, turn off both `strict` and `warnings`. We can reduce this to either 317 bytes (or 315 bytes) ```perl -(@_=split'/'),push@{$d{$_[0]}},-d?"$_[1]/":$_[1]for<*/*>;$u{$_}++for map{@{$d{$_}}}my@p=sort keys%d;$l;$lkeys%{$u{$l}}?sprintf$b,map{$u{$l}{$_}?$l:''}@p:()}sort@_),$a ``` -This is the 317 byte version - we could reduce it to 315 bytes by replacing +This is the 242 byte version - we could reduce it to 240 bytes by replacing `print` with `say` again... But ultimately that makes the execution more bytes. Command line with `print`: -- cgit