diff options
| -rw-r--r-- | challenge-007/ozzy/perl6/ch-1.p6 | 20 |
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); + } +} |
