diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-06-14 02:45:45 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-14 02:45:45 +0100 |
| commit | 5faf35c89f25a11af5c86998b40f467f8d6e62ed (patch) | |
| tree | f00d0edeebac54e68d7fcbf9021e2578018f95a7 /challenge-116/abigail/python | |
| parent | 67e781df5703c3644c28980b49984f72fc552aee (diff) | |
| parent | c8a301ef5457abb3e84793c169234e01d839e9bb (diff) | |
| download | perlweeklychallenge-club-5faf35c89f25a11af5c86998b40f467f8d6e62ed.tar.gz perlweeklychallenge-club-5faf35c89f25a11af5c86998b40f467f8d6e62ed.tar.bz2 perlweeklychallenge-club-5faf35c89f25a11af5c86998b40f467f8d6e62ed.zip | |
Merge pull request #4248 from Abigail/abigail/week-116
Abigail/week 116
Diffstat (limited to 'challenge-116/abigail/python')
| -rw-r--r-- | challenge-116/abigail/python/ch-1.py | 33 | ||||
| -rw-r--r-- | challenge-116/abigail/python/ch-2.py | 23 |
2 files changed, 56 insertions, 0 deletions
diff --git a/challenge-116/abigail/python/ch-1.py b/challenge-116/abigail/python/ch-1.py new file mode 100644 index 0000000000..b988189564 --- /dev/null +++ b/challenge-116/abigail/python/ch-1.py @@ -0,0 +1,33 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-1.py < input-file +# + +import fileinput + +def make_sequence (string, start): + if string == start: + return [start] + + if 0 == string . find (start): + tail = string [len (start) :] + result = make_sequence (tail, str (int (start) + 1)) or \ + make_sequence (tail, str (int (start) - 1)) + if result: + return [start] + result + + return None + + +for line in fileinput . input (): + line = line . strip () + for i in range (0, len (line)): + result = make_sequence (line, line [0 : i + 1]) + if result: + print ("," . join (result)) + break diff --git a/challenge-116/abigail/python/ch-2.py b/challenge-116/abigail/python/ch-2.py new file mode 100644 index 0000000000..0876b16b64 --- /dev/null +++ b/challenge-116/abigail/python/ch-2.py @@ -0,0 +1,23 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-2.py < input-file +# + +import fileinput +from math import sqrt + +for line in fileinput . input (): + sum_of_squares = 0 + for char in line: + if "1" <= char and char <= "9": + sum_of_squares = sum_of_squares + int (char) * int (char) + root = int (.5 + sqrt (sum_of_squares)) + if sum_of_squares == root * root: + print (1) + else: + print (0) |
