diff options
| author | Paulo Custodio <pauloscustodio@gmail.com> | 2024-09-27 16:40:19 +0100 |
|---|---|---|
| committer | Paulo Custodio <pauloscustodio@gmail.com> | 2024-09-27 16:40:19 +0100 |
| commit | 9f334ddeefd0261373f90dfd1815c48f836cade9 (patch) | |
| tree | 6e8fad4f4a832996dfd89387dbd69750372ce75d /challenge-153/paulo-custodio/python/ch-1.py | |
| parent | 4b61c9ed07a7c3faa5a5587c35c7b9164956d111 (diff) | |
| download | perlweeklychallenge-club-9f334ddeefd0261373f90dfd1815c48f836cade9.tar.gz perlweeklychallenge-club-9f334ddeefd0261373f90dfd1815c48f836cade9.tar.bz2 perlweeklychallenge-club-9f334ddeefd0261373f90dfd1815c48f836cade9.zip | |
Add Python solution to challenge 153
Diffstat (limited to 'challenge-153/paulo-custodio/python/ch-1.py')
| -rw-r--r-- | challenge-153/paulo-custodio/python/ch-1.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/challenge-153/paulo-custodio/python/ch-1.py b/challenge-153/paulo-custodio/python/ch-1.py new file mode 100644 index 0000000000..054f47cfb3 --- /dev/null +++ b/challenge-153/paulo-custodio/python/ch-1.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + +# Challenge 153 +# +# TASK #1 > Left Factorials +# Submitted by: Mohammad S Anwar +# Write a script to compute Left Factorials of 1 to 10. Please refer +# OEIS A003422 for more information. +# +# Expected Output: +# 1, 2, 4, 10, 34, 154, 874, 5914, 46234, 409114 + +def fact(n): + if n < 2: + return 1 + else: + return n * fact(n-1) + +def left_fact(n): + sum = 0 + for k in range(n): + sum += fact(k) + return sum + +out = [left_fact(x) for x in range(1, 10+1)] +print(", ".join(map(str, out))) |
