aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlakpatashi <lakpatashi@gmail.com>2021-04-18 00:08:28 +0530
committerlakpatashi <lakpatashi@gmail.com>2021-04-18 00:08:28 +0530
commitae0337ec1d83898d206f8b9482058bf654a29b1d (patch)
tree452bde544f521cbf6346ce2ed043a27a6b3f4d60
parent42cec2beb33d0ca9179dab7660f57ca46b170797 (diff)
downloadperlweeklychallenge-club-ae0337ec1d83898d206f8b9482058bf654a29b1d.tar.gz
perlweeklychallenge-club-ae0337ec1d83898d206f8b9482058bf654a29b1d.tar.bz2
perlweeklychallenge-club-ae0337ec1d83898d206f8b9482058bf654a29b1d.zip
Finished challenge-009 with perl
-rw-r--r--challenge-009/lakpatashi/README1
-rwxr-xr-xchallenge-009/lakpatashi/perl/ch-1.pl25
-rwxr-xr-xchallenge-009/lakpatashi/perl/ch-2.pl49
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";
+}
+