diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2023-01-29 11:11:28 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-29 11:11:28 +0000 |
| commit | 324bbbe76db93583db46923456ca8a9d39cadb2f (patch) | |
| tree | 160cee42e8227cc94e27c13eadaba003cb4b6d99 | |
| parent | 2a9b53d3c95b9980bb63807179bda21b96f1ad9e (diff) | |
| parent | 61c5939605b4a1b77cef4d1da10a57d29593cec1 (diff) | |
| download | perlweeklychallenge-club-324bbbe76db93583db46923456ca8a9d39cadb2f.tar.gz perlweeklychallenge-club-324bbbe76db93583db46923456ca8a9d39cadb2f.tar.bz2 perlweeklychallenge-club-324bbbe76db93583db46923456ca8a9d39cadb2f.zip | |
Merge pull request #7474 from atothrp/branch-for-challenge-201
Branch for challenge 201
| -rw-r--r-- | challenge-200/arpad-toth/perl/ch-1.pl | 23 | ||||
| -rw-r--r-- | challenge-200/arpad-toth/perl/ch-2.pl | 105 | ||||
| -rw-r--r-- | challenge-201/arpad-toth/ch200-1.pl | 21 | ||||
| -rw-r--r-- | challenge-201/arpad-toth/ch200-2.pl | 103 | ||||
| -rw-r--r-- | challenge-201/arpad-toth/ch201-1.pl | 22 | ||||
| -rw-r--r-- | challenge-201/arpad-toth/ch201-2.pl | 5 |
6 files changed, 279 insertions, 0 deletions
diff --git a/challenge-200/arpad-toth/perl/ch-1.pl b/challenge-200/arpad-toth/perl/ch-1.pl new file mode 100644 index 0000000000..b4725b1766 --- /dev/null +++ b/challenge-200/arpad-toth/perl/ch-1.pl @@ -0,0 +1,23 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use feature 'say'; + +#usage : perl script 1 2 3 4 + +my @o=@ARGV; +push my @slc,$o[0],$o[1]; +sub sayno{say "no slice found"}; +sayno if scalar(@ARGV)<3; +my $fl=0; + +#build slices +while(scalar(@o)>=2){ + my $delta=$o[1]-$o[0]; + for(2..$#o){push @slc,$o[$_] and say "(@slc)" and $fl=1 if($o[$_]-$o[$_-1] == $delta) || last}; + splice(@o,0,1); + undef(@slc);push @slc,$o[0],$o[1]; +} +$fl==1 ? exit : sayno; + diff --git a/challenge-200/arpad-toth/perl/ch-2.pl b/challenge-200/arpad-toth/perl/ch-2.pl new file mode 100644 index 0000000000..5ca6cef36c --- /dev/null +++ b/challenge-200/arpad-toth/perl/ch-2.pl @@ -0,0 +1,105 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use feature 'say'; + +#usage : perl script 2 0 0 + +# line1 +for(0..$#ARGV){ +if($ARGV[$_] == 1 +or $ARGV[$_] == 4){&space7;if($_<$#ARGV){&space};if($_==$#ARGV){print "\n"}}; + +if($ARGV[$_] == 2 +or $ARGV[$_] == 3 +or $ARGV[$_] == 5 +or $ARGV[$_] == 6 +or $ARGV[$_] == 7 +or $ARGV[$_] == 8 +or $ARGV[$_] == 9 +or $ARGV[$_] == 0){&draw_147;if($_<$#ARGV){&space};if($_==$#ARGV){print "\n"}}; +} + +# line23 +for(1..2){ +for(0..$#ARGV){ +if($ARGV[$_] == 5 +or $ARGV[$_] == 6){&draw_2356_l;if($_<$#ARGV){&space};if($_==$#ARGV){print "\n"}}; + +if($ARGV[$_] == 1 +or $ARGV[$_] == 2 +or $ARGV[$_] == 3 +or $ARGV[$_] == 7){&draw_2356_r;if($_<$#ARGV){&space};if($_==$#ARGV){print "\n"}}; + +if($ARGV[$_] == 4 +or $ARGV[$_] == 8 +or $ARGV[$_] == 9 +or $ARGV[$_] == 0){&draw_2356_b;if($_<$#ARGV){&space};if($_==$#ARGV){print "\n"}}; +} +} + +# line4 +for(0..$#ARGV){ +if($ARGV[$_] == 2 +or $ARGV[$_] == 3 +or $ARGV[$_] == 4 +or $ARGV[$_] == 5 +or $ARGV[$_] == 6 +or $ARGV[$_] == 8 +or $ARGV[$_] == 9){&draw_147;if($_<$#ARGV){&space};if($_==$#ARGV){print "\n"}}; + +if($ARGV[$_] == 1 +or $ARGV[$_] == 7 +or $ARGV[$_] == 0){&space7;if($_<$#ARGV){&space};if($_==$#ARGV){print "\n"}}; +} +# line56 +for(1..2){ +for(0..$#ARGV){ +if($ARGV[$_] == 2){&draw_2356_l;if($_<$#ARGV){&space};if($_==$#ARGV){print "\n"}}; + +if($ARGV[$_] == 1 +or $ARGV[$_] == 3 +or $ARGV[$_] == 4 +or $ARGV[$_] == 5 +or $ARGV[$_] == 7 +or $ARGV[$_] == 9){&draw_2356_r;if($_<$#ARGV){&space};if($_==$#ARGV){print "\n"}}; + +if($ARGV[$_] == 6 +or $ARGV[$_] == 8 +or $ARGV[$_] == 0){&draw_2356_b;if($_<$#ARGV){&space};if($_==$#ARGV){print "\n"}}; +} +} + +# line7 +for(0..$#ARGV){ +if($ARGV[$_] == 1 +or $ARGV[$_] == 4 +or $ARGV[$_] == 7){&space7;if($_<$#ARGV){&space};if($_==$#ARGV){print "\n"}}; + +if($ARGV[$_] == 2 +or $ARGV[$_] == 3 +or $ARGV[$_] == 5 +or $ARGV[$_] == 6 +or $ARGV[$_] == 8 +or $ARGV[$_] == 9 +or $ARGV[$_] == 0){&draw_147;if($_<$#ARGV){&space};if($_==$#ARGV){print "\n"}}; +} + +# line1 - (2,3,5,6,7,8,9,0) - (-------) +# line2,3 -left - (5,6) - (|) +# line2,3 -right- (1,2,3,7) - (|) +# line2,3 -both-(4,8,9,0) (| |) +# line4 - (2,3,4,5,6,8,9) - (-------) +# line5,6 -left - (2) - (|) +# line5,6 -right - (1,3,4,5,7,9) (|) +# line5,5 -both-(6,8,0) (| |) +# line7 - (2,3,5,6,8,9,0) - (-------) + +sub draw_147{print "-"x7}; +sub draw_2356_l{printf"%-7s","|"}; +sub draw_2356_r{printf"%7s","|"}; +sub draw_2356_b{printf"%s","| |"}; +sub space{print " "}; +sub space7{print " "x7}; + diff --git a/challenge-201/arpad-toth/ch200-1.pl b/challenge-201/arpad-toth/ch200-1.pl new file mode 100644 index 0000000000..5d2bf7fa07 --- /dev/null +++ b/challenge-201/arpad-toth/ch200-1.pl @@ -0,0 +1,21 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use feature 'say'; + +my @o=@ARGV; +push my @slc,$o[0],$o[1]; +sub sayno{say "no slice found"}; +sayno if scalar(@ARGV)<3; +my $fl=0; + +#build slices +while(scalar(@o)>=2){ + my $delta=$o[1]-$o[0]; + for(2..$#o){push @slc,$o[$_] and say "(@slc)" and $fl=1 if($o[$_]-$o[$_-1] == $delta) || last}; + splice(@o,0,1); + undef(@slc);push @slc,$o[0],$o[1]; +} +$fl==1 ? exit : sayno; + diff --git a/challenge-201/arpad-toth/ch200-2.pl b/challenge-201/arpad-toth/ch200-2.pl new file mode 100644 index 0000000000..7e18da211c --- /dev/null +++ b/challenge-201/arpad-toth/ch200-2.pl @@ -0,0 +1,103 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use feature 'say'; + +# line1 +for(0..$#ARGV){ +if($ARGV[$_] == 1 +or $ARGV[$_] == 4){&space7;if($_<$#ARGV){&space};if($_==$#ARGV){print "\n"}}; + +if($ARGV[$_] == 2 +or $ARGV[$_] == 3 +or $ARGV[$_] == 5 +or $ARGV[$_] == 6 +or $ARGV[$_] == 7 +or $ARGV[$_] == 8 +or $ARGV[$_] == 9 +or $ARGV[$_] == 0){&draw_147;if($_<$#ARGV){&space};if($_==$#ARGV){print "\n"}}; +} + +# line23 +for(1..2){ +for(0..$#ARGV){ +if($ARGV[$_] == 5 +or $ARGV[$_] == 6){&draw_2356_l;if($_<$#ARGV){&space};if($_==$#ARGV){print "\n"}}; + +if($ARGV[$_] == 1 +or $ARGV[$_] == 2 +or $ARGV[$_] == 3 +or $ARGV[$_] == 7){&draw_2356_r;if($_<$#ARGV){&space};if($_==$#ARGV){print "\n"}}; + +if($ARGV[$_] == 4 +or $ARGV[$_] == 8 +or $ARGV[$_] == 9 +or $ARGV[$_] == 0){&draw_2356_b;if($_<$#ARGV){&space};if($_==$#ARGV){print "\n"}}; +} +} + +# line4 +for(0..$#ARGV){ +if($ARGV[$_] == 2 +or $ARGV[$_] == 3 +or $ARGV[$_] == 4 +or $ARGV[$_] == 5 +or $ARGV[$_] == 6 +or $ARGV[$_] == 8 +or $ARGV[$_] == 9){&draw_147;if($_<$#ARGV){&space};if($_==$#ARGV){print "\n"}}; + +if($ARGV[$_] == 1 +or $ARGV[$_] == 7 +or $ARGV[$_] == 0){&space7;if($_<$#ARGV){&space};if($_==$#ARGV){print "\n"}}; +} +# line56 +for(1..2){ +for(0..$#ARGV){ +if($ARGV[$_] == 2){&draw_2356_l;if($_<$#ARGV){&space};if($_==$#ARGV){print "\n"}}; + +if($ARGV[$_] == 1 +or $ARGV[$_] == 3 +or $ARGV[$_] == 4 +or $ARGV[$_] == 5 +or $ARGV[$_] == 7 +or $ARGV[$_] == 9){&draw_2356_r;if($_<$#ARGV){&space};if($_==$#ARGV){print "\n"}}; + +if($ARGV[$_] == 6 +or $ARGV[$_] == 8 +or $ARGV[$_] == 0){&draw_2356_b;if($_<$#ARGV){&space};if($_==$#ARGV){print "\n"}}; +} +} + +# line7 +for(0..$#ARGV){ +if($ARGV[$_] == 1 +or $ARGV[$_] == 4 +or $ARGV[$_] == 7){&space7;if($_<$#ARGV){&space};if($_==$#ARGV){print "\n"}}; + +if($ARGV[$_] == 2 +or $ARGV[$_] == 3 +or $ARGV[$_] == 5 +or $ARGV[$_] == 6 +or $ARGV[$_] == 8 +or $ARGV[$_] == 9 +or $ARGV[$_] == 0){&draw_147;if($_<$#ARGV){&space};if($_==$#ARGV){print "\n"}}; +} + +# line1 - (2,3,5,6,7,8,9,0) - (-------) +# line2,3 -left - (5,6) - (|) +# line2,3 -right- (1,2,3,7) - (|) +# line2,3 -both-(4,8,9,0) (| |) +# line4 - (2,3,4,5,6,8,9) - (-------) +# line5,6 -left - (2) - (|) +# line5,6 -right - (1,3,4,5,7,9) (|) +# line5,5 -both-(6,8,0) (| |) +# line7 - (2,3,5,6,8,9,0) - (-------) + +sub draw_147{print "-"x7}; +sub draw_2356_l{printf"%-7s","|"}; +sub draw_2356_r{printf"%7s","|"}; +sub draw_2356_b{printf"%s","| |"}; +sub space{print " "}; +sub space7{print " "x7}; + diff --git a/challenge-201/arpad-toth/ch201-1.pl b/challenge-201/arpad-toth/ch201-1.pl new file mode 100644 index 0000000000..aeb0123ba6 --- /dev/null +++ b/challenge-201/arpad-toth/ch201-1.pl @@ -0,0 +1,22 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use feature 'say'; + +#usage 'perl script 1,2,10,3' + +my @list = sort {$a <=> $b} split( /,/, join(',',@ARGV) ); + +my %lookup = map { $_ => undef } @list; + +say "the range is 0..$list[-1]"; +print "the missing number(s) are/is "; + +for(0..$list[-1]){ + unless ( exists $lookup{ $_ }) { + print "$_ "} +} + +say ""; + diff --git a/challenge-201/arpad-toth/ch201-2.pl b/challenge-201/arpad-toth/ch201-2.pl new file mode 100644 index 0000000000..d1ad647402 --- /dev/null +++ b/challenge-201/arpad-toth/ch201-2.pl @@ -0,0 +1,5 @@ +# tried to do this w a one liner :) +# +perl -E '@a=(1,1,1,1,1,1,1,1);say @a;@o=@a;for($i=2;$i<=scalar(@o);$i++){splice(@a,0,$i,$i);say @a;for(1..$#a){last if $a[$_+1]==undef;splice(@a,$_,2,$a[$_]+$a[$_+1]);@b=@a;if($a[0]>=3 and $b[$_+1]!=undef){splice(@b,$_,2,$b[$_]+$b[$_+1]);say @b};say @a};@a=@o}' + + |
