diff options
| author | Simon Green <mail@simon.green> | 2022-02-27 22:05:50 +1100 |
|---|---|---|
| committer | Simon Green <mail@simon.green> | 2022-02-27 22:05:50 +1100 |
| commit | ffcd75115810ad7757864de93b29ce8b829750bd (patch) | |
| tree | cad8032021393c70b08b134209b33049df91c74e | |
| parent | 69f7b1bee1117ea3ec8f7701570e5c85d8147e90 (diff) | |
| download | perlweeklychallenge-club-ffcd75115810ad7757864de93b29ce8b829750bd.tar.gz perlweeklychallenge-club-ffcd75115810ad7757864de93b29ce8b829750bd.tar.bz2 perlweeklychallenge-club-ffcd75115810ad7757864de93b29ce8b829750bd.zip | |
sgreen solutions to challenge 153
| -rw-r--r-- | challenge-153/sgreen/README.md | 2 | ||||
| -rw-r--r-- | challenge-153/sgreen/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-153/sgreen/python/ch-1.py | 13 | ||||
| -rwxr-xr-x | challenge-153/sgreen/python/ch-2.py | 17 |
4 files changed, 32 insertions, 1 deletions
diff --git a/challenge-153/sgreen/README.md b/challenge-153/sgreen/README.md index f87b671575..e8deece95f 100644 --- a/challenge-153/sgreen/README.md +++ b/challenge-153/sgreen/README.md @@ -1,3 +1,3 @@ # The Weekly Challenge 152 -Blog: [Triangles and Rectangles](https://dev.to/simongreennet/triangles-and-rectangles-45p8) +Blog: [Factorials everywhere!](https://dev.to/simongreennet/factorials-everywhere-5gga) diff --git a/challenge-153/sgreen/blog.txt b/challenge-153/sgreen/blog.txt new file mode 100644 index 0000000000..7df912c76e --- /dev/null +++ b/challenge-153/sgreen/blog.txt @@ -0,0 +1 @@ +https://dev.to/simongreennet/factorials-everywhere-5gga
\ No newline at end of file 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 |
