From 9f334ddeefd0261373f90dfd1815c48f836cade9 Mon Sep 17 00:00:00 2001 From: Paulo Custodio Date: Fri, 27 Sep 2024 16:40:19 +0100 Subject: Add Python solution to challenge 153 --- challenge-153/paulo-custodio/python/ch-1.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 challenge-153/paulo-custodio/python/ch-1.py (limited to 'challenge-153/paulo-custodio/python/ch-1.py') 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))) -- cgit