aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander <39702500+threadless-screw@users.noreply.github.com>2019-05-06 07:45:05 +0000
committerGitHub <noreply@github.com>2019-05-06 07:45:05 +0000
commitf51bc114c8c8e04f6e0221ab47319675afdf57a9 (patch)
tree35392769c925c7bfde8119a0ab5e0ae6d2cee635
parentfd0c2d3740978f4bff1c6f88f003b50a1486b167 (diff)
downloadperlweeklychallenge-club-f51bc114c8c8e04f6e0221ab47319675afdf57a9.tar.gz
perlweeklychallenge-club-f51bc114c8c8e04f6e0221ab47319675afdf57a9.tar.bz2
perlweeklychallenge-club-f51bc114c8c8e04f6e0221ab47319675afdf57a9.zip
ch-1.p6
-rw-r--r--challenge-007/ozzy/perl6/ch-1.p620
1 files changed, 20 insertions, 0 deletions
diff --git a/challenge-007/ozzy/perl6/ch-1.p6 b/challenge-007/ozzy/perl6/ch-1.p6
new file mode 100644
index 0000000000..ef3380f92b
--- /dev/null
+++ b/challenge-007/ozzy/perl6/ch-1.p6
@@ -0,0 +1,20 @@
+#/usr/bin/env perl6
+
+# Print all the niven numbers from 0 to 50 inclusive, each on their own line.
+# A niven number is a non-negative number that is divisible by the sum of its digits.
+
+sub SumDigits ( Int $x is copy ) {
+ my $sum=0;
+ while $x != 0 {
+ $sum += $x mod 10;
+ $x= $x div 10;
+ }
+ return $sum;
+}
+
+
+sub MAIN {
+ for 0..50 -> $x {
+ say $x if $x %% SumDigits($x);
+ }
+}