summaryrefslogtreecommitdiff
path: root/021/ch1.pl
diff options
context:
space:
mode:
Diffstat (limited to '021/ch1.pl')
-rwxr-xr-x021/ch1.pl19
1 files changed, 19 insertions, 0 deletions
diff --git a/021/ch1.pl b/021/ch1.pl
new file mode 100755
index 0000000..86b5ef3
--- /dev/null
+++ b/021/ch1.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl
+#
+# Write a script to calculate the value of e, also known as Euler’s number and
+# Napier’s constant. Please checkout wiki page for more information.
+################################################################################
+
+use strict;
+use warnings;
+
+my $ITERS = shift or die "Usage: $0 <iterations>";
+
+my $e = 1;
+my $denom = 1;
+foreach my $i (1 .. $ITERS) {
+ $denom *= $i;
+ $e += 1/$denom;
+}
+
+print "$e\n";