aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-03-17 13:52:37 +0000
committerGitHub <noreply@github.com>2024-03-17 13:52:37 +0000
commit24b0c58d2dc13cbc482e6309d349e1322beb7912 (patch)
tree70fbc6be01a5f70d7e006de51aa199fcde3ad3a4
parentbe9ae7459b347030a14bf444ebdecda1cb5a3983 (diff)
parent7be4d35fb8b6c00d67e99390206ec30aaa1fe1f3 (diff)
downloadperlweeklychallenge-club-24b0c58d2dc13cbc482e6309d349e1322beb7912.tar.gz
perlweeklychallenge-club-24b0c58d2dc13cbc482e6309d349e1322beb7912.tar.bz2
perlweeklychallenge-club-24b0c58d2dc13cbc482e6309d349e1322beb7912.zip
Merge pull request #9751 from adamcrussell/challenge-260
initial commit
-rw-r--r--challenge-260/adam-russell/blog.txt1
-rw-r--r--challenge-260/adam-russell/perl/ch-1.pl23
-rw-r--r--challenge-260/adam-russell/perl/ch-2.pl46
3 files changed, 70 insertions, 0 deletions
diff --git a/challenge-260/adam-russell/blog.txt b/challenge-260/adam-russell/blog.txt
new file mode 100644
index 0000000000..e8920bea37
--- /dev/null
+++ b/challenge-260/adam-russell/blog.txt
@@ -0,0 +1 @@
+http://www.rabbitfarm.com/cgi-bin/blosxom/perl/2024/03/16 \ No newline at end of file
diff --git a/challenge-260/adam-russell/perl/ch-1.pl b/challenge-260/adam-russell/perl/ch-1.pl
new file mode 100644
index 0000000000..a09cbd1695
--- /dev/null
+++ b/challenge-260/adam-russell/perl/ch-1.pl
@@ -0,0 +1,23 @@
+
+
+use v5.38;
+use boolean;
+
+
+sub unique_occurrences{
+ my %occurrences;
+ do{
+ $occurrences{$_}++;
+ } for @_;
+ my %h;
+ do{$h{$_} = undef} for values %occurrences;
+ return boolean(values %occurrences == keys %h);
+}
+
+
+MAIN:{
+ say unique_occurrences 1, 2, 2, 1, 1, 3;
+ say unique_occurrences 1, 2, 3;
+ say unique_occurrences -2, 0, 1, -2, 1, 1, 0, 1, -2, 9;
+}
+
diff --git a/challenge-260/adam-russell/perl/ch-2.pl b/challenge-260/adam-russell/perl/ch-2.pl
new file mode 100644
index 0000000000..00a597feda
--- /dev/null
+++ b/challenge-260/adam-russell/perl/ch-2.pl
@@ -0,0 +1,46 @@
+
+
+use v5.38;
+use boolean;
+
+
+sub permutations{
+ my($a, $k, $permutations) = @_;
+ if($k == 1){
+ push @{$permutations}, [@{$a}];
+ return true;
+ }
+ else{
+ permutations($a, $k - 1, $permutations);
+ for my $i (0 .. $k - 2){
+ if($k & 1){
+ ($a->[0], $a->[$k - 1]) = ($a->[$k - 1], $a->[0]);
+ }
+ else{
+ ($a->[$i], $a->[$k - 1]) = ($a->[$k - 1], $a->[$i]);
+ }
+ permutations($a, $k - 1, $permutations);
+ }
+ }
+}
+
+
+sub dictionary_rank{
+ my($word) = @_;
+ my $permutations = [];
+ permutations [split //, $word], length($word), $permutations;
+ my %h;
+ do {$h{join q//, @{$_}} = undef} for @{$permutations};
+ my @permutations = sort {$a cmp $b} keys %h;
+ return (
+ grep {$permutations[$_] eq $word} 0 .. @permutations - 1
+ )[0] + 1;
+}
+
+
+MAIN:{
+ say dictionary_rank q/CAT/;
+ say dictionary_rank q/GOOGLE/;
+ say dictionary_rank q/SECRET/;
+}
+