diff options
| author | Abigail <abigail@abigail.be> | 2021-11-05 20:58:51 +0100 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-11-05 20:58:51 +0100 |
| commit | a0298e354570ba3ebf90abaeaf9f2af3b58702e7 (patch) | |
| tree | b0aaf38d1443e4d6cf21dd5dc476a5fa2c65e974 /challenge-133/abigail/python | |
| parent | 62496f0a55d58841ca5b56cc386a329285d8e35d (diff) | |
| download | perlweeklychallenge-club-a0298e354570ba3ebf90abaeaf9f2af3b58702e7.tar.gz perlweeklychallenge-club-a0298e354570ba3ebf90abaeaf9f2af3b58702e7.tar.bz2 perlweeklychallenge-club-a0298e354570ba3ebf90abaeaf9f2af3b58702e7.zip | |
AWK, Bash, Lua, Node.js, Python and Ruby solutions for week 133, part 2.
Diffstat (limited to 'challenge-133/abigail/python')
| -rw-r--r-- | challenge-133/abigail/python/ch-2.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/challenge-133/abigail/python/ch-2.py b/challenge-133/abigail/python/ch-2.py new file mode 100644 index 0000000000..7fd37368d9 --- /dev/null +++ b/challenge-133/abigail/python/ch-2.py @@ -0,0 +1,40 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-2.py < input-file +# + +def digit_sum (numbers): + sum = 0 + for num in numbers: + while num > 0: + sum = sum + num % 10 + num = num // 10 + return (sum) + +small_primes = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31) + +def factorize (num): + out = [] + for prime in small_primes: + while num % prime == 0: + out . append (prime) + num = num / prime + if num > 1: + out . append (num) + return (out) + + +number = 1 +count = 0 + +while count < 10: + factors = factorize (number) + if len (factors) > 1 and digit_sum ([number]) == digit_sum (factors): + print (number) + count = count + 1 + number = number + 1 |
