diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-04-17 19:47:54 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-04-17 19:47:54 +0100 |
| commit | dc5224413ae261499213f86ffaee9122abb9b65a (patch) | |
| tree | bf6a2def96e428da6628bae2337ad4daece2c65b | |
| parent | c41d315cb4b91cd5a4bca875cb848c2a0a211501 (diff) | |
| parent | ae0337ec1d83898d206f8b9482058bf654a29b1d (diff) | |
| download | perlweeklychallenge-club-dc5224413ae261499213f86ffaee9122abb9b65a.tar.gz perlweeklychallenge-club-dc5224413ae261499213f86ffaee9122abb9b65a.tar.bz2 perlweeklychallenge-club-dc5224413ae261499213f86ffaee9122abb9b65a.zip | |
Merge pull request #3906 from lakpatashi/branch-009
Finished challenge-009 with perl
| -rw-r--r-- | challenge-009/lakpatashi/README | 1 | ||||
| -rwxr-xr-x | challenge-009/lakpatashi/perl/ch-1.pl | 25 | ||||
| -rwxr-xr-x | challenge-009/lakpatashi/perl/ch-2.pl | 49 |
3 files changed, 75 insertions, 0 deletions
diff --git a/challenge-009/lakpatashi/README b/challenge-009/lakpatashi/README new file mode 100644 index 0000000000..bc153bd576 --- /dev/null +++ b/challenge-009/lakpatashi/README @@ -0,0 +1 @@ +Solution by lakpatashi diff --git a/challenge-009/lakpatashi/perl/ch-1.pl b/challenge-009/lakpatashi/perl/ch-1.pl new file mode 100755 index 0000000000..41d6d19a72 --- /dev/null +++ b/challenge-009/lakpatashi/perl/ch-1.pl @@ -0,0 +1,25 @@ +#!/usr/bin/perl + +use warnings; +use strict; + +#part 1 + +my ($i,$count) = (1,0); +for (;;){ + my $n = $i**2; + if(uniqDigCount($n) > 4){ + print "$i**2 ==> $n\n"; + $count++; + } + $i++; + last if $count == 1; +} + +sub uniqDigCount{ + my @list = split '', shift; + my %seen = (); + my @uniqu = grep { ! $seen{$_} ++ } @list; + return $#uniqu+1; +} + diff --git a/challenge-009/lakpatashi/perl/ch-2.pl b/challenge-009/lakpatashi/perl/ch-2.pl new file mode 100755 index 0000000000..c5b3bb067e --- /dev/null +++ b/challenge-009/lakpatashi/perl/ch-2.pl @@ -0,0 +1,49 @@ +#!/usr/bin/perl + +use warnings; +use strict; + +#part 2 +use Data::Dumper; +use feature qw(switch); +print "\n\n"; +my @points = (20,10,40,20); +print "Points List: ",join(' ', @points), "\n"; +my $code1 = 'std'; +my $code2 = 'mod'; +my $code3 = 'den'; +Rank(\@points,$code1); +Rank(\@points,$code2); +Rank(\@points,$code3); + +sub Rank{ + my ($arr ,$code) = @_; + @_ = @{$arr}; + print "Ranking $code\n"; + my %pointHash; + ++$pointHash{$_} for @_; + #print Dumper(\%pointHash); + my $rank = 1; + if( $code =~ 'mod' ){ + $rank = 0; + } + print "Rank Points\n"; + for my $point (sort {$b<=>$a} keys %pointHash ){ + given($code){ + when('std') { #std 1224 + print "$rank ==> $point\n"x $pointHash{$point}; + $rank += $pointHash{$point}; + } + when('mod') { #modified 1334 + $rank += $pointHash{$point}; + print "$rank ==> $point\n"x $pointHash{$point}; + } + when('den') { #dense 1223 + print "$rank ==> $point\n"x $pointHash{$point}; + $rank++; + } + } + } + print '-'x10,"\n\n"; +} + |
