diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-05-12 10:00:48 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-12 10:00:48 +0100 |
| commit | e25a806961f90ca121de0ac7650a522355843f6e (patch) | |
| tree | 037651e93fe51d3d3c67d70b73fec2974b816daf | |
| parent | ac0db43bdafd2bc5b0748155495a901b9ebaf94e (diff) | |
| parent | 7bea5ff392f56d61f6334766a56d088e4fb21a97 (diff) | |
| download | perlweeklychallenge-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/README | 1 | ||||
| -rwxr-xr-x | challenge-021/lakpatashi/perl/ch-1.pl | 33 |
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); +} + + |
