diff options
| -rw-r--r-- | challenge-111/abigail/README.md | 1 | ||||
| -rw-r--r-- | challenge-111/abigail/python/ch-1.py | 31 |
2 files changed, 32 insertions, 0 deletions
diff --git a/challenge-111/abigail/README.md b/challenge-111/abigail/README.md index a7ac678775..45e924351b 100644 --- a/challenge-111/abigail/README.md +++ b/challenge-111/abigail/README.md @@ -37,6 +37,7 @@ languages, the fact input is sorted does not offer additional benefits. * [Lua](lua/ch-1.lua) * [Node.js](node/ch-1.js) * [Perl](perl/ch-1.pl) +* [Python](python/ch-1.py) ### Blog diff --git a/challenge-111/abigail/python/ch-1.py b/challenge-111/abigail/python/ch-1.py new file mode 100644 index 0000000000..ba91c8009f --- /dev/null +++ b/challenge-111/abigail/python/ch-1.py @@ -0,0 +1,31 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-1.py < input-file +# + +MATRIX_SIZE = 5 + +import fileinput +import re + +# +# Read in the matrix +# +matrix = {} +for i in range (MATRIX_SIZE): + for n in re . findall (r'-?[0-9]+', input ()): + matrix [n] = 1 + +# +# For the rest of the input, check whether it's in the matrix +# +for line in fileinput . input (): + if line . strip () in matrix: + print ("1") + else: + print ("0") |
