From f51bc114c8c8e04f6e0221ab47319675afdf57a9 Mon Sep 17 00:00:00 2001 From: Alexander <39702500+threadless-screw@users.noreply.github.com> Date: Mon, 6 May 2019 07:45:05 +0000 Subject: ch-1.p6 --- challenge-007/ozzy/perl6/ch-1.p6 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 challenge-007/ozzy/perl6/ch-1.p6 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); + } +} -- cgit