aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-153/paulo-custodio/perl/ch-1.pl2
-rw-r--r--challenge-153/paulo-custodio/perl/ch-2.pl2
-rw-r--r--challenge-153/paulo-custodio/python/ch-1.py26
-rw-r--r--challenge-153/paulo-custodio/python/ch-2.py41
4 files changed, 69 insertions, 2 deletions
diff --git a/challenge-153/paulo-custodio/perl/ch-1.pl b/challenge-153/paulo-custodio/perl/ch-1.pl
index 29f2d4ed37..07f81c2860 100644
--- a/challenge-153/paulo-custodio/perl/ch-1.pl
+++ b/challenge-153/paulo-custodio/perl/ch-1.pl
@@ -2,7 +2,7 @@
# Challenge 153
#
-# TASK #1 › Left Factorials
+# 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.
diff --git a/challenge-153/paulo-custodio/perl/ch-2.pl b/challenge-153/paulo-custodio/perl/ch-2.pl
index 95631b0e51..e87e4bd435 100644
--- a/challenge-153/paulo-custodio/perl/ch-2.pl
+++ b/challenge-153/paulo-custodio/perl/ch-2.pl
@@ -2,7 +2,7 @@
# Challenge 153
#
-# TASK #2 › Factorions
+# TASK #2 > Factorions
# Submitted by: Mohammad S Anwar
# You are given an integer, $n.
#
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)))
diff --git a/challenge-153/paulo-custodio/python/ch-2.py b/challenge-153/paulo-custodio/python/ch-2.py
new file mode 100644
index 0000000000..cafb749fac
--- /dev/null
+++ b/challenge-153/paulo-custodio/python/ch-2.py
@@ -0,0 +1,41 @@
+#!/usr/bin/env python3
+
+# Challenge 153
+#
+# TASK #2 > Factorions
+# Submitted by: Mohammad S Anwar
+# You are given an integer, $n.
+#
+# Write a script to figure out if the given integer is factorion.
+#
+# A factorion is a natural number that equals the sum of the factorials
+# of its digits.
+#
+# Example 1:
+# Input: $n = 145
+# Output: 1
+#
+# Since 1! + 4! + 5! => 1 + 24 + 120 = 145
+# Example 2:
+# Input: $n = 123
+# Output: 0
+#
+# Since 1! + 2! + 3! => 1 + 2 + 6 <> 123
+
+import sys
+
+def fact(n):
+ if n < 2:
+ return 1
+ else:
+ return n * fact(n-1)
+
+def is_factorian(n):
+ fact_sum = [fact(int(x)) for x in str(n)]
+ if sum(fact_sum) == n:
+ return True
+ else:
+ return False
+
+n = int(sys.argv[1])
+print(1 if is_factorian(n) else 0)