diff options
| -rw-r--r-- | challenge-199/arpad-toth/perl/ch-1.sh | 15 | ||||
| -rw-r--r-- | challenge-199/arpad-toth/perl/ch-2.sh | 11 |
2 files changed, 26 insertions, 0 deletions
diff --git a/challenge-199/arpad-toth/perl/ch-1.sh b/challenge-199/arpad-toth/perl/ch-1.sh new file mode 100644 index 0000000000..d57e32b612 --- /dev/null +++ b/challenge-199/arpad-toth/perl/ch-1.sh @@ -0,0 +1,15 @@ +# https://theweeklychallenge.org/blog/perl-weekly-challenge-199/ +# challenge #1 +# quick one-liner + +# example 1: +perl -E '$i=$c=0;while($i<=$#ARGV){for($i..$#ARGV){$c++ if $ARGV[$i]==$ARGV[$_+1]};$i++;};say $c' 1 2 3 1 1 3 +# output: 4 + +# example 2: +perl -E '$i=$c=0;while($i<=$#ARGV){for($i..$#ARGV){$c++ if $ARGV[$i]==$ARGV[$_+1]};$i++;};say $c' 1 2 3 +# output: 0 + +# example 3: +perl -E '$i=$c=0;while($i<=$#ARGV){for($i..$#ARGV){$c++ if $ARGV[$i]==$ARGV[$_+1]};$i++;};say $c' 1 1 1 1 +# output: 6 diff --git a/challenge-199/arpad-toth/perl/ch-2.sh b/challenge-199/arpad-toth/perl/ch-2.sh new file mode 100644 index 0000000000..85db2169e3 --- /dev/null +++ b/challenge-199/arpad-toth/perl/ch-2.sh @@ -0,0 +1,11 @@ +# https://theweeklychallenge.org/blog/perl-weekly-challenge-199/ +# challenge #2 +# again a quick one-liner + +# example 1: +perl -E '$c=0;$x=7;$y=2;$z=3;$i=0;$j=1;$k=2;while($#ARGV>=0){while($k<=$#ARGV){for($k..$#ARGV){$c++ if(abs($ARGV[$i]-$ARGV[$j])<=$x && abs($ARGV[$j]-$ARGV[$_])<=$y && abs($ARGV[$i]-$ARGV[$_])<=$z)};$j++;$k++};$i=0;$j=1;$k=2;splice(@ARGV,0,1)};say $c' 3 0 1 1 9 7 +# output :4 + +# example 2: +perl -E '$c=0;$x=0;$y=0;$z=1;$i=0;$j=1;$k=2;while($#ARGV>=0){while($k<=$#ARGV){for($k..$#ARGV){$c++ if(abs($ARGV[$i]-$ARGV[$j])<=$x && abs($ARGV[$j]-$ARGV[$_])<=$y && abs($ARGV[$i]-$ARGV[$_])<=$z)};$j++;$k++};$i=0;$j=1;$k=2;splice(@ARGV,0,1)};say $c' 1 1 2 2 3 +# output :0 |
