diff options
| author | Abigail <abigail@abigail.be> | 2021-11-02 00:41:39 +0100 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-11-02 00:41:39 +0100 |
| commit | fc52f6b569892b44d0f934ae795c199f2b7d3a53 (patch) | |
| tree | b7da3678ee715b70410ca9cedda32283f000f35b | |
| parent | 6b972ea8100cf12dfdc2f92dbf8ba66dc3c98725 (diff) | |
| download | perlweeklychallenge-club-fc52f6b569892b44d0f934ae795c199f2b7d3a53.tar.gz perlweeklychallenge-club-fc52f6b569892b44d0f934ae795c199f2b7d3a53.tar.bz2 perlweeklychallenge-club-fc52f6b569892b44d0f934ae795c199f2b7d3a53.zip | |
Python solutions for week 137
| -rw-r--r-- | challenge-137/abigail/python/ch-1.py | 36 | ||||
| -rw-r--r-- | challenge-137/abigail/python/ch-2.py | 29 |
2 files changed, 65 insertions, 0 deletions
diff --git a/challenge-137/abigail/python/ch-1.py b/challenge-137/abigail/python/ch-1.py new file mode 100644 index 0000000000..e7fe2c5b94 --- /dev/null +++ b/challenge-137/abigail/python/ch-1.py @@ -0,0 +1,36 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-1.py +# + + +start_years = [1600, 2000] +long_year_offsets = [ + 4, 9, 15, 20, 26, + 32, 37, 43, 48, 54, + 60, 65, 71, 76, 82, + 88, 93, 99, + 105, 111, 116, 122, + 128, 133, 139, 144, 150, + 156, 161, 167, 172, 178, + 184, 189, 195, + 201, 207, 212, 218, + 224, 229, 235, 240, 246, + 252, 257, 263, 268, 274, + 280, 285, 291, 296, + 303, 308, 314, + 320, 325, 331, 336, 342, + 348, 353, 359, 364, 370, + 376, 381, 387, 392, 398 +] + +for start_year in start_years: + for offset in long_year_offsets: + year = start_year + offset + if 1900 <= year <= 2100: + print (year) diff --git a/challenge-137/abigail/python/ch-2.py b/challenge-137/abigail/python/ch-2.py new file mode 100644 index 0000000000..8e27559fbf --- /dev/null +++ b/challenge-137/abigail/python/ch-2.py @@ -0,0 +1,29 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-2.py < input-file +# + +import fileinput + +def reverse (num): + rev = 0 + while num > 0: + rev = rev * 10 + (num % 10) + num = num // 10 + return rev + + +def ly (num): + if num >= 10000000: + return 1 + if num == reverse (num): + return 0 + return ly (num + reverse (num)) + +for number in fileinput . input (): + print (ly (int (number))) |
