From 6d7e1942a22328ba6c83e771d113957909eaabcf Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 21 Feb 2022 13:37:03 +0100 Subject: Solutions for week 153 --- challenge-153/abigail/python/ch-1.py | 23 +++++++++++++++++++++++ challenge-153/abigail/python/ch-2.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 challenge-153/abigail/python/ch-1.py create mode 100644 challenge-153/abigail/python/ch-2.py (limited to 'challenge-153/abigail/python') diff --git a/challenge-153/abigail/python/ch-1.py b/challenge-153/abigail/python/ch-1.py new file mode 100644 index 0000000000..6f287fa129 --- /dev/null +++ b/challenge-153/abigail/python/ch-1.py @@ -0,0 +1,23 @@ +#!/usr/local/bin/python3 + +# +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-153 +# + +# +# Run as: python ch-1.py +# + +import sys; + +fac = 1 +sum = 1 + +sys . stdout . write (str (sum)) + +for n in range (1, 10): + fac = fac * n + sum = sum + fac + sys . stdout . write (" " + str (sum)) + +sys . stdout . write ("\n") diff --git a/challenge-153/abigail/python/ch-2.py b/challenge-153/abigail/python/ch-2.py new file mode 100644 index 0000000000..693eeffe7f --- /dev/null +++ b/challenge-153/abigail/python/ch-2.py @@ -0,0 +1,28 @@ +#!/usr/local/bin/python3 + +# +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-153 +# + +# +# Run as: python ch-2.py < input-file +# + +import fileinput + +fac = [1] * 10 +for n in range (1, 10): + fac [n] = n * fac [n - 1] + +for line in fileinput . input (): + num = int (line) + sum = 0 + n = num + while n > 0: + sum = sum + fac [n % 10] + n = n // 10 + + if num == sum: + print (1) + else: + print (0) -- cgit