aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-05-12 10:00:48 +0100
committerGitHub <noreply@github.com>2021-05-12 10:00:48 +0100
commite25a806961f90ca121de0ac7650a522355843f6e (patch)
tree037651e93fe51d3d3c67d70b73fec2974b816daf
parentac0db43bdafd2bc5b0748155495a901b9ebaf94e (diff)
parent7bea5ff392f56d61f6334766a56d088e4fb21a97 (diff)
downloadperlweeklychallenge-club-e25a806961f90ca121de0ac7650a522355843f6e.tar.gz
perlweeklychallenge-club-e25a806961f90ca121de0ac7650a522355843f6e.tar.bz2
perlweeklychallenge-club-e25a806961f90ca121de0ac7650a522355843f6e.zip
Merge pull request #4064 from lakpatashi/challenge-021
Finished challenge-021 ch-1 only with perl
-rw-r--r--challenge-021/lakpatashi/README1
-rwxr-xr-xchallenge-021/lakpatashi/perl/ch-1.pl33
2 files changed, 34 insertions, 0 deletions
diff --git a/challenge-021/lakpatashi/README b/challenge-021/lakpatashi/README
new file mode 100644
index 0000000000..bc153bd576
--- /dev/null
+++ b/challenge-021/lakpatashi/README
@@ -0,0 +1 @@
+Solution by lakpatashi
diff --git a/challenge-021/lakpatashi/perl/ch-1.pl b/challenge-021/lakpatashi/perl/ch-1.pl
new file mode 100755
index 0000000000..c51c29b389
--- /dev/null
+++ b/challenge-021/lakpatashi/perl/ch-1.pl
@@ -0,0 +1,33 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+use Data::Dumper;
+use List::Util qw(max min sum);
+use feature qw(switch);
+use Memoize;
+memoize qw( factorial );
+#part 1
+my $e;
+my $iterLimit = 100;
+for my $i (0..$iterLimit){
+ $e += exponTerm( $i );
+ if( $i == $iterLimit ){
+ print "value of e after $iterLimit iteration => $e\n"
+ }
+}
+
+sub exponTerm{
+ my ($n) = @_;
+ return 1/factorial($n);
+}
+
+sub factorial{
+ my ($n) = @_;
+ if( $n < 2 ){
+ return 1;
+ }
+ return $n * factorial($n-1);
+}
+
+