blob: 490ced41c367a96b0bb1871491f9f2f284ebc274 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#!/usr/bin/env perl
#
# 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
################################################################################
use strict;
use warnings;
use List::Util qw(reduce);
sub niven {
my $n = shift;
return 0 if $n == 0;
$n % (reduce { $a + $b } split(//, $n)) == 0;
}
foreach (grep { niven $_ } (0..50)) {
print $_, "\n";
}
|