diff options
| author | lakpatashi <lakpatashi@gmail.com> | 2021-04-14 01:25:38 +0530 |
|---|---|---|
| committer | lakpatashi <lakpatashi@gmail.com> | 2021-04-14 01:25:38 +0530 |
| commit | 4dc3b4aead653a946e6fcf4f480296080827375c (patch) | |
| tree | e8ea01b0c91b9542b07445ac405ab50620a8adc9 /challenge-003 | |
| parent | 4f5a6326cd97c1aa247d1c974e9730696922bfc0 (diff) | |
| download | perlweeklychallenge-club-4dc3b4aead653a946e6fcf4f480296080827375c.tar.gz perlweeklychallenge-club-4dc3b4aead653a946e6fcf4f480296080827375c.tar.bz2 perlweeklychallenge-club-4dc3b4aead653a946e6fcf4f480296080827375c.zip | |
challenge-003 finished in perl
Diffstat (limited to 'challenge-003')
| -rwxr-xr-x | challenge-003/lakpatashi/ch-1.pl | 19 | ||||
| -rwxr-xr-x | challenge-003/lakpatashi/ch-2.pl | 35 |
2 files changed, 54 insertions, 0 deletions
diff --git a/challenge-003/lakpatashi/ch-1.pl b/challenge-003/lakpatashi/ch-1.pl new file mode 100755 index 0000000000..bc76cc8bcf --- /dev/null +++ b/challenge-003/lakpatashi/ch-1.pl @@ -0,0 +1,19 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +# PART 1 +my $range = 5; #max exponent of each prime factor +my @arr; +for my $i (0..$range){ + for my $j (0..$range){ + for my $k (0..$range){ + push @arr, 2**$i * 3**$j * 5**$k; + } + } +} +print join ' ',sort {$a<=>$b} @arr; +print "\n"; + + diff --git a/challenge-003/lakpatashi/ch-2.pl b/challenge-003/lakpatashi/ch-2.pl new file mode 100755 index 0000000000..32545f3617 --- /dev/null +++ b/challenge-003/lakpatashi/ch-2.pl @@ -0,0 +1,35 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +# PART 2 +print "\n\n"; +my $n; +if($#ARGV >= 0){ + $n = shift; + die "<rows> must be at least 3\n" if $n<3; + my $line = '1'; + for my $i (reverse 0..$n-1){ + #print ' ' x $i, "$i\n"; + $line = PascalNext($line) if $i <$n-1; + print ' ' x $i, $line,"\n"; + } +}else{ + print "Usage: ./ch-1.pl <row-no>\n"; +} + +sub PascalNext{ + my $line = shift; #scalar string + #print $line,"\n"; + my @arr = split ' ', $line; + unshift @arr, 0; + push @arr,0; + + my @newArr; + for my $i (1..$#arr){ + push @newArr, $arr[$i-1] + $arr[$i]; + } + return join " ",@newArr; +} +#print "\n var:: $n\n"; |
