From ffcd75115810ad7757864de93b29ce8b829750bd Mon Sep 17 00:00:00 2001 From: Simon Green Date: Sun, 27 Feb 2022 22:05:50 +1100 Subject: sgreen solutions to challenge 153 --- challenge-153/sgreen/python/ch-2.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 challenge-153/sgreen/python/ch-2.py (limited to 'challenge-153/sgreen/python/ch-2.py') diff --git a/challenge-153/sgreen/python/ch-2.py b/challenge-153/sgreen/python/ch-2.py new file mode 100755 index 0000000000..3937a647c4 --- /dev/null +++ b/challenge-153/sgreen/python/ch-2.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python + +import math +import sys + +def main(n): + # Check we have an integer >= 0 + num = int(n) + if num < 0: + raise ValueError("You must specify a non-negative integer") + + # Get the sum of factorials of each digit + s = sum(math.factorial(int(x)) for x in n) + print('1' if s == num else 0) + +if __name__ == '__main__': + main(sys.argv[1]) \ No newline at end of file -- cgit