From 563cb2f865dcb3e10e7fe0cd3d8ca60a3e02e407 Mon Sep 17 00:00:00 2001 From: Abigail Date: Thu, 4 Nov 2021 18:12:56 +0100 Subject: Bash, bc, C, Lua, Node.js, Python and Ruby solutions for week 133, part 1. --- challenge-133/abigail/python/ch-1.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 challenge-133/abigail/python/ch-1.py (limited to 'challenge-133/abigail/python') diff --git a/challenge-133/abigail/python/ch-1.py b/challenge-133/abigail/python/ch-1.py new file mode 100644 index 0000000000..9fc7b1c3fd --- /dev/null +++ b/challenge-133/abigail/python/ch-1.py @@ -0,0 +1,15 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-1.py < input-file +# + +import fileinput +import math + +for num in fileinput . input (): + print (math . floor (math . exp (math . log (int (num)) / 2))) -- cgit From a0298e354570ba3ebf90abaeaf9f2af3b58702e7 Mon Sep 17 00:00:00 2001 From: Abigail Date: Fri, 5 Nov 2021 20:58:51 +0100 Subject: AWK, Bash, Lua, Node.js, Python and Ruby solutions for week 133, part 2. --- challenge-133/abigail/python/ch-2.py | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 challenge-133/abigail/python/ch-2.py (limited to 'challenge-133/abigail/python') 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 -- cgit