summaryrefslogtreecommitdiff
path: root/007/ch1.pl
diff options
context:
space:
mode:
Diffstat (limited to '007/ch1.pl')
-rwxr-xr-x007/ch1.pl16
1 files changed, 16 insertions, 0 deletions
diff --git a/007/ch1.pl b/007/ch1.pl
new file mode 100755
index 0000000..8102da6
--- /dev/null
+++ b/007/ch1.pl
@@ -0,0 +1,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";
+}