From 158e2b79cc16f52dd755457be2a39eaa669de421 Mon Sep 17 00:00:00 2001 From: Abigail Date: Mon, 24 Jan 2022 21:17:26 +0100 Subject: Week 149, part 2: Solutions in 16 languages. --- challenge-149/abigail/python/ch-2.py | 42 ++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 challenge-149/abigail/python/ch-2.py (limited to 'challenge-149/abigail/python') diff --git a/challenge-149/abigail/python/ch-2.py b/challenge-149/abigail/python/ch-2.py new file mode 100644 index 0000000000..68b490cfa4 --- /dev/null +++ b/challenge-149/abigail/python/ch-2.py @@ -0,0 +1,42 @@ +#!/usr/local/bin/python3 + +# +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-149 +# + +# +# Run as: python ch-2.py < input-file +# + +A287298 = {} + +A287298 [ 2] = "1" +A287298 [ 3] = "1" +A287298 [ 4] = "3201" +A287298 [ 5] = "4301" +A287298 [ 6] = "452013" +A287298 [ 7] = "6250341" +A287298 [ 8] = "47302651" +A287298 [ 9] = "823146570" +A287298 [10] = "9814072356" +A287298 [11] = "A8701245369" +A287298 [12] = "B8750A649321" +A287298 [13] = "CBA504216873" +A287298 [14] = "DC71B30685A924" +A287298 [15] = "EDAC93B24658701" +A287298 [16] = "FED5B39A42706C81" +A287298 [17] = "GFED5A31C6B79802" +A287298 [18] = "HGF80ADC53712EB649" +A287298 [19] = "IHGFD3408C6E715A2B9" +A287298 [20] = "JIHG03DAC457BFE96281" +A287298 [22] = "LKJIG5D14B9032FHAC867E" + + +import fileinput + +for n in fileinput . input (): + n = int (n) + if n in A287298: + print (A287298 [n]) + else: + print ("Too hard to calculate") -- cgit From f6f8fa27a551ad1171389cc9ca8b5c9a0e39e025 Mon Sep 17 00:00:00 2001 From: Abigail Date: Tue, 25 Jan 2022 13:09:57 +0100 Subject: Week 149, part 1: More solutions bc, C, Go, Java, Lua, Node.js, Pascal, Python, R, Ruby, Scheme, and Tcl. --- challenge-149/abigail/python/ch-1.py | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 challenge-149/abigail/python/ch-1.py (limited to 'challenge-149/abigail/python') diff --git a/challenge-149/abigail/python/ch-1.py b/challenge-149/abigail/python/ch-1.py new file mode 100644 index 0000000000..1a7f8d33ac --- /dev/null +++ b/challenge-149/abigail/python/ch-1.py @@ -0,0 +1,45 @@ +#!/usr/local/bin/python3 + +# +# See https://theweeklychallenge.org/blog/perl-weekly-challenge-149 +# + +# +# Run as: python ch-1.py < input-file +# + + +def digit_sum (number): + sum = 0 + base = 10 + while number > 0: + sum = sum + number % base + number = number // base + return sum + +fib = {} +fib_prev = 0 +fib_last = 1 +fib [fib_prev] = True; +fib [fib_last] = True; + +def is_fib (n): + global fib, fib_prev, fib_last + while fib_last < n: + t = fib_last + fib_last = fib_last + fib_prev + fib_prev = t + fib [fib_last] = True; + return n in fib + +import fileinput, sys + +for n in fileinput . input (): + n = int (n) + k = 0 + while n > 0: + if is_fib (digit_sum (k)): + sys . stdout . write (str (k) + " ") + n = n - 1 + k = k + 1 + print ("") -- cgit