summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillermo Ramos2019-08-12 21:39:23 +0200
committerGuillermo Ramos2019-08-12 21:39:23 +0200
commit6d0ba18b52f0c430617f9640da11810da8075c98 (patch)
tree60172a2c23c2c67edb5e0ffb2b5d0e7afda795bd
parent5b23e44824c4c74da7942be3ca215c4b12cd9641 (diff)
downloadperlweekly-6d0ba18b52f0c430617f9640da11810da8075c98.tar.gz
[021#1]
-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";