aboutsummaryrefslogtreecommitdiff
path: root/challenge-166
diff options
context:
space:
mode:
authordrbaggy <js5@sanger.ac.uk>2022-05-29 12:09:51 +0100
committerdrbaggy <js5@sanger.ac.uk>2022-05-29 12:09:51 +0100
commit7937cd47b86930bbc266be4b4a2e266316f848b5 (patch)
treebc80a14fdb0e96f89060e30ccaf4bdb8c2ce6035 /challenge-166
parent8db1bb377c8e8302ae3e998e8fc674b9d45a6041 (diff)
parentaf25eaa47101aee0e03f6d271dd42611b023cd36 (diff)
downloadperlweeklychallenge-club-7937cd47b86930bbc266be4b4a2e266316f848b5.tar.gz
perlweeklychallenge-club-7937cd47b86930bbc266be4b4a2e266316f848b5.tar.bz2
perlweeklychallenge-club-7937cd47b86930bbc266be4b4a2e266316f848b5.zip
Merge branch 'master' of github.com:drbaggy/perlweeklychallenge-club
Diffstat (limited to 'challenge-166')
-rw-r--r--challenge-166/james-smith/README.md24
1 files changed, 15 insertions, 9 deletions
diff --git a/challenge-166/james-smith/README.md b/challenge-166/james-smith/README.md
index 82352a1088..2c0c2c9927 100644
--- a/challenge-166/james-smith/README.md
+++ b/challenge-166/james-smith/README.md
@@ -329,21 +329,22 @@ discussions with Eliza on the Perl Programmers Facebook group and things
slowly got smaller. A few bytes at a time to the 272 byte:
```perl
-sub x{my($l,$F,%d,%u,@p)=0;/\//,$u{$'.'/'x-d}{$d{$`}=$`}++for<*/*>;$l<length?$l=
-length:1for(@p=sort keys%d),@_=keys%u;print$a=join('-'x$l,('+--')x@p,"+\n"),
-sprintf($b="| %-${l}s "x@p."|\n",@p),$a,map({$l=$_;@p>keys%{$u{$l}}?sprintf$b,
-map{$u{$l}{$_}?$l:''}@p:()}sort@_),$a}
+123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789-
+sub z{my($l,$F,%d,%u,@p)=0;/\//,$u{$'.'/'x-d}{$d{$`}=$`}++for<*/*>;$l<length?$l=
+length:1for(@p=sort keys%d),@_=keys%u;say$a=join('-'x$l,('+--')x@p,"+\n"),
+sprintf($b="| %-${l}s "x@p."\n",@p),$a,map({//;@p-%{$u{$'}}?sprintf$b,map{$' x
+$u{$'}{$_}}@p:()}sort@_),$a}
```
**or** if we "allow" return characters inside strings - this is 270 bytes of
perly goodness...
```perl
-sub z{my($l,$F,%d,%u,@p)=0;/\//,$u{$'.'/'x-d}{$d{$`}=$`}++for<*/*>;$l<length?$l=
-length:1for(@p=sort keys%d),@_=keys%u;print$a=join('-'x$l,('+--')x@p,'+
+sub z{my($l,$F,%d,%u,@p)=0;/\//,$u{$'.'/'x-d}{$d{$`}=$`}++for<*/*>;
+$l<length?$l=length:1for(@p=sort keys%d),@_=keys%u;
+print$a=join('-'x$l,('+--')x@p,'+
'),sprintf($b="| %-${l}s "x@p.'|
-',@p),$a,map({$l=$_;@p>keys%{$u{$l}}?sprintf$b,map{$u{$l}{$_}?$l:''}@p:()}sort@_
-),$a}
+',@p),$a,map({//;@p-%{$u{$'}}?sprintf$b,map{$' x$u{$'}{$_}}@p:()}sort@_),$a}
```
**Notes**
@@ -355,7 +356,12 @@ length:1for(@p=sort keys%d),@_=keys%u;print$a=join('-'x$l,('+--')x@p,'+
`1 for @array` as `1for@array`.
- we don't need to do `sort blob '*/*'` or `sort <*/*>` as for all "current"
versions of Perl we can assume that perl does this for us.
-
+ - Rather than using `split /\//`, we use the match operator `/\//` in one place
+ and `//` in another to split - the first half goes in `$`` and the second half
+ in `$'`.
+ - When using `//` this just copies `$_` into `$'`.
+ - if you subtract a hash in scalar context then it subtracts the numbers of keys.
+ Sp we can compute the number ot times a file is missing by doing `@p-%u`.
## Coda - taking the brakes off...
For ultimate compactness we can remove the function overhead off, turn off both