From d4dfd166ab137d9e8f007cd5c2c422cdee06abd3 Mon Sep 17 00:00:00 2001 From: James Smith Date: Sat, 10 Apr 2021 11:10:33 +0100 Subject: Update ch-1.pl --- challenge-107/james-smith/perl/ch-1.pl | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/challenge-107/james-smith/perl/ch-1.pl b/challenge-107/james-smith/perl/ch-1.pl index fff417572c..a791fd9a95 100644 --- a/challenge-107/james-smith/perl/ch-1.pl +++ b/challenge-107/james-smith/perl/ch-1.pl @@ -1,3 +1,36 @@ +Skip to content +Search or jump to… + +Pull requests +Issues +Marketplace +Explore + +@drbaggy +drbaggy +/ +perlweeklychallenge-club +forked from manwar/perlweeklychallenge-club +0 +0 +204 +Code +Pull requests +Actions +Projects +Wiki +Security +Insights +Settings +perlweeklychallenge-club/challenge-107/james-smith/perl/ch-1.pl +@drbaggy +drbaggy Documentation, some more golfing on ch-2 and an example of the differ… +… +Latest commit 2b79dbf 4 days ago + History + 1 contributor +129 lines (113 sloc) 4.16 KB + #!/usr/local/bin/perl use strict; @@ -116,6 +149,7 @@ perl -E '($c-join"",map{0+(@Q=$c=~/($_)/g)}0..-1+length$c)||++$n&&say$c while++$ ## ## * To gain another character as the equality is numeric we can ## rewrite if($a==$b) { f() } as ($a-$b)||f(). +## ## $a-$b is non-zero (true) if $a!=$b so we can rewrite: ## ## if( $a == $b ) { f() } @@ -127,3 +161,10 @@ perl -E '($c-join"",map{0+(@Q=$c=~/($_)/g)}0..-1+length$c)||++$n&&say$c while++$ ## which we know we mentioned we could rewrite as: ## ## ($a-$b) || f() +## +## The brackets are important o/w this evaluates to: +## +## $a-($b||f()) +## +## which isn't what we want... +## -- cgit