aboutsummaryrefslogtreecommitdiff
path: root/challenge-043
diff options
context:
space:
mode:
authorSimon Proctor <simon.proctor@zpg.co.uk>2020-01-13 11:16:33 +0000
committerSimon Proctor <simon.proctor@zpg.co.uk>2020-01-13 11:16:33 +0000
commitc79525030ea6d637b206d2825ed85e3a8255f14b (patch)
tree1c0e7463f1c85608f9221d39095af6ebb06b440a /challenge-043
parenta8405922ed66ae8f5d8da0b492cd3b6bd26f75fb (diff)
downloadperlweeklychallenge-club-c79525030ea6d637b206d2825ed85e3a8255f14b.tar.gz
perlweeklychallenge-club-c79525030ea6d637b206d2825ed85e3a8255f14b.tar.bz2
perlweeklychallenge-club-c79525030ea6d637b206d2825ed85e3a8255f14b.zip
Self descriptive numbers
Diffstat (limited to 'challenge-043')
-rw-r--r--challenge-043/simon-proctor/raku/ch-2.p620
1 files changed, 20 insertions, 0 deletions
diff --git a/challenge-043/simon-proctor/raku/ch-2.p6 b/challenge-043/simon-proctor/raku/ch-2.p6
new file mode 100644
index 0000000000..3cd3eb2a05
--- /dev/null
+++ b/challenge-043/simon-proctor/raku/ch-2.p6
@@ -0,0 +1,20 @@
+#!/usr/bin/enb perl6
+
+use v6;
+
+#| Calculate the self desscriptive number for the given base
+sub MAIN( UInt \base where 1 <= * <= 36 ) {
+ say calculate( base );
+}
+
+# No number available for these bases
+multi calculate( \base where * ~~ 1|2|3|6 ) {
+ "No self descriptive number for base {base}";
+}
+
+multi calculate(4) { "Either 1210 or 2020" }
+multi calculate(5) { "21200" }
+
+multi calculate(\base) {
+ ((base-4)*(base**(base-1))+(2*(base**(base-2)))+(base**(base-3))+(base**3)).base(base);
+}