aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-07-24 02:00:20 +0100
committerGitHub <noreply@github.com>2022-07-24 02:00:20 +0100
commit54ee4024f2e859154713eae501fc66ccd0a9cd9a (patch)
treed37261707aaefbe51840d4537d2afe2d6afc4aba
parent802241bb296dec2bd9dbc785b045469d7731f6dd (diff)
parenta3569417753c3b16944ef66851d248ffd0bdb507 (diff)
downloadperlweeklychallenge-club-54ee4024f2e859154713eae501fc66ccd0a9cd9a.tar.gz
perlweeklychallenge-club-54ee4024f2e859154713eae501fc66ccd0a9cd9a.tar.bz2
perlweeklychallenge-club-54ee4024f2e859154713eae501fc66ccd0a9cd9a.zip
Merge pull request #6486 from arnesom/branch-for-challenge-174
Arne Sommer
-rw-r--r--challenge-174/arne-sommer/blog.txt1
-rwxr-xr-xchallenge-174/arne-sommer/raku/ch-1.raku20
-rwxr-xr-xchallenge-174/arne-sommer/raku/ch-2.raku25
-rwxr-xr-xchallenge-174/arne-sommer/raku/disarium-sequence20
-rwxr-xr-xchallenge-174/arne-sommer/raku/permutation-ranking25
5 files changed, 91 insertions, 0 deletions
diff --git a/challenge-174/arne-sommer/blog.txt b/challenge-174/arne-sommer/blog.txt
new file mode 100644
index 0000000000..61ccca2765
--- /dev/null
+++ b/challenge-174/arne-sommer/blog.txt
@@ -0,0 +1 @@
+https://raku-musings.com/disarmed-ranking.html
diff --git a/challenge-174/arne-sommer/raku/ch-1.raku b/challenge-174/arne-sommer/raku/ch-1.raku
new file mode 100755
index 0000000000..bd434dddaf
--- /dev/null
+++ b/challenge-174/arne-sommer/raku/ch-1.raku
@@ -0,0 +1,20 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (Int $count where $count > 0 = 19);
+
+my $ds := (^Inf).grep( *.&is-disarium );
+
+say $ds[^$count].join(", ");
+
+sub is-disarium ($number)
+{
+ my $position = 0;
+ my $sum = 0;
+
+ for $number.comb -> $digit
+ {
+ $sum += $digit ** ++$position;
+ }
+
+ return $sum == $number;
+}
diff --git a/challenge-174/arne-sommer/raku/ch-2.raku b/challenge-174/arne-sommer/raku/ch-2.raku
new file mode 100755
index 0000000000..4e4fc36cad
--- /dev/null
+++ b/challenge-174/arne-sommer/raku/ch-2.raku
@@ -0,0 +1,25 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (*@i where all(@i) ~~ Int && ! @i.repeated, :$r, :v(:$verbose));
+
+say permutation2rank(@i);
+say rank2permutation(@i, $r);
+
+sub permutation2rank(@list)
+{
+ my @p = @list.sort.permutations;
+
+ for ^@p.elems -> $index
+ {
+ say ": $index -> @p[$index]" if $verbose;
+ return $index if @p[$index] cmp @list == 0;
+ }
+}
+
+sub rank2permutation(@list, $index)
+{
+ my @p = @list.sort.permutations;
+
+ return @p[$index];
+
+} \ No newline at end of file
diff --git a/challenge-174/arne-sommer/raku/disarium-sequence b/challenge-174/arne-sommer/raku/disarium-sequence
new file mode 100755
index 0000000000..bd434dddaf
--- /dev/null
+++ b/challenge-174/arne-sommer/raku/disarium-sequence
@@ -0,0 +1,20 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (Int $count where $count > 0 = 19);
+
+my $ds := (^Inf).grep( *.&is-disarium );
+
+say $ds[^$count].join(", ");
+
+sub is-disarium ($number)
+{
+ my $position = 0;
+ my $sum = 0;
+
+ for $number.comb -> $digit
+ {
+ $sum += $digit ** ++$position;
+ }
+
+ return $sum == $number;
+}
diff --git a/challenge-174/arne-sommer/raku/permutation-ranking b/challenge-174/arne-sommer/raku/permutation-ranking
new file mode 100755
index 0000000000..4e4fc36cad
--- /dev/null
+++ b/challenge-174/arne-sommer/raku/permutation-ranking
@@ -0,0 +1,25 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (*@i where all(@i) ~~ Int && ! @i.repeated, :$r, :v(:$verbose));
+
+say permutation2rank(@i);
+say rank2permutation(@i, $r);
+
+sub permutation2rank(@list)
+{
+ my @p = @list.sort.permutations;
+
+ for ^@p.elems -> $index
+ {
+ say ": $index -> @p[$index]" if $verbose;
+ return $index if @p[$index] cmp @list == 0;
+ }
+}
+
+sub rank2permutation(@list, $index)
+{
+ my @p = @list.sort.permutations;
+
+ return @p[$index];
+
+} \ No newline at end of file