From e674b457aa9a8912365f1ac52a1eaf4e3d386ddc Mon Sep 17 00:00:00 2001 From: Abigail Date: Tue, 4 May 2021 12:04:46 +0200 Subject: Python solution for week 111, part 2 --- challenge-111/abigail/python/ch-2.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 challenge-111/abigail/python/ch-2.py (limited to 'challenge-111/abigail/python') diff --git a/challenge-111/abigail/python/ch-2.py b/challenge-111/abigail/python/ch-2.py new file mode 100644 index 0000000000..ce79d6b393 --- /dev/null +++ b/challenge-111/abigail/python/ch-2.py @@ -0,0 +1,35 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-2.py < input-file +# + +import fileinput +import string +import re + + +# +# Create a pattern which matches words with their characters in lexical order. +# +pat = "^" +for x in list (string . ascii_lowercase): + pat = pat + x + "*" +pat += "$" + + +# +# Match strings with their characters in lexical order, and remember +# the longest of them. +# +longest = "" +for line in fileinput . input (): + line = line . strip () + if re . match (pat, line . lower ()) and len (line) > len (longest): + longest = line + +print (longest) -- cgit From c740d8f54a4355f0d4b58715962541ea9c473597 Mon Sep 17 00:00:00 2001 From: Abigail Date: Tue, 4 May 2021 17:49:26 +0200 Subject: Python solution for week 111, part 1 --- challenge-111/abigail/python/ch-1.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 challenge-111/abigail/python/ch-1.py (limited to 'challenge-111/abigail/python') 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") -- cgit