diff options
| author | drbaggy <js5@sanger.ac.uk> | 2022-02-28 06:42:52 +0000 |
|---|---|---|
| committer | drbaggy <js5@sanger.ac.uk> | 2022-02-28 06:42:52 +0000 |
| commit | 79466de7ef71946f9ef6acd21d9b80fede2d7ef3 (patch) | |
| tree | fc7250288695fe29a2fe4294bb6371ccd28c46b4 /challenge-153/sgreen/python | |
| parent | ad4031ad944a6ee247c953c7d3e8c98e27fe5f23 (diff) | |
| parent | 708f0b09a688c48e140d552c4116678099bb0581 (diff) | |
| download | perlweeklychallenge-club-79466de7ef71946f9ef6acd21d9b80fede2d7ef3.tar.gz perlweeklychallenge-club-79466de7ef71946f9ef6acd21d9b80fede2d7ef3.tar.bz2 perlweeklychallenge-club-79466de7ef71946f9ef6acd21d9b80fede2d7ef3.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-153/sgreen/python')
| -rwxr-xr-x | challenge-153/sgreen/python/ch-1.py | 13 | ||||
| -rwxr-xr-x | challenge-153/sgreen/python/ch-2.py | 17 |
2 files changed, 30 insertions, 0 deletions
diff --git a/challenge-153/sgreen/python/ch-1.py b/challenge-153/sgreen/python/ch-1.py new file mode 100755 index 0000000000..453072fc92 --- /dev/null +++ b/challenge-153/sgreen/python/ch-1.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python + +import math + +def main(): + solutions = [1] + for i in range(1, 10): + solutions.append(solutions[-1]+math.factorial(i)) + + print(*solutions, sep=', ') + +if __name__ == '__main__': + main()
\ No newline at end of file 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 |
