aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-04-11 17:29:32 +0100
committerGitHub <noreply@github.com>2021-04-11 17:29:32 +0100
commit6150b90485dc26e2bff5b6b723cce0a739a00d8e (patch)
tree48156329e7c40d11579ec0ddfaf733a5fecfdbbd
parentd27a93fc6fda833e39eeac456a979b5464d00f85 (diff)
parent8aa868c5b8c67d6453303d441343ac9895cf5b69 (diff)
downloadperlweeklychallenge-club-6150b90485dc26e2bff5b6b723cce0a739a00d8e.tar.gz
perlweeklychallenge-club-6150b90485dc26e2bff5b6b723cce0a739a00d8e.tar.bz2
perlweeklychallenge-club-6150b90485dc26e2bff5b6b723cce0a739a00d8e.zip
Merge pull request #3864 from andemark/branch-for-challenge-107
ch-1.raku again...
-rw-r--r--challenge-107/mark-anderson/raku/ch-1.raku31
1 files changed, 26 insertions, 5 deletions
diff --git a/challenge-107/mark-anderson/raku/ch-1.raku b/challenge-107/mark-anderson/raku/ch-1.raku
index 559f74d305..816d8c0ca5 100644
--- a/challenge-107/mark-anderson/raku/ch-1.raku
+++ b/challenge-107/mark-anderson/raku/ch-1.raku
@@ -1,13 +1,34 @@
#!/usr/bin/env raku
-say (^Inf).grep(&self-descriptive).head(3);
+say (1..36).map(&self-descriptive).flat.head(3);
-sub self-descriptive($n)
+multi self-descriptive($base where * == 1|2|3|6)
{
- for ^$n.chars
+ Empty;
+}
+
+multi self-descriptive($base where * == 4|5)
+{
+ my $start = (1 ~ 0 x $base - 1).parse-base($base);
+ my $end = ($base - 1 ~ 0 x $base - 1).parse-base($base);
+
+ gather
{
- return False unless $n.substr($_, 1) == $n.indices($_);
+ while $start < $end
+ {
+ my $multiple = $start.base($base);
+
+ take $multiple if all map
+ {
+ $multiple.substr($_, 1) == $multiple.indices($_)
+ }, ^$base;
+
+ $start += $base;
+ }
}
+}
- True;
+multi self-descriptive($base)
+{
+ ($base - 4).base(36) ~ 21 ~ 0 x $base - 7 ~ 1000;
}