diff options
| author | atothrp <atoth20@cogeco.ca> | 2023-01-12 19:35:59 -0500 |
|---|---|---|
| committer | atothrp <atoth20@cogeco.ca> | 2023-01-12 19:35:59 -0500 |
| commit | 72499b4035e1d6099cfedcf8eb0469bb1e1c9ce9 (patch) | |
| tree | 0d4ff17e24fec296a549b88cc2f36b276dd359c3 | |
| parent | 13e4a2c007d7a0aac2bd1b8a48aa28003d772dc5 (diff) | |
| download | perlweeklychallenge-club-72499b4035e1d6099cfedcf8eb0469bb1e1c9ce9.tar.gz perlweeklychallenge-club-72499b4035e1d6099cfedcf8eb0469bb1e1c9ce9.tar.bz2 perlweeklychallenge-club-72499b4035e1d6099cfedcf8eb0469bb1e1c9ce9.zip | |
perl5 solutions for week 199
| -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 |
