summaryrefslogtreecommitdiff
path: root/007/ch1.pl
blob: 8102da6495c4458ef0ac738512cc9226ede3e28a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/env perl

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";
}