diff options
| -rwxr-xr-x | challenge-128/stuart-little/python/ch-1.py | 19 | ||||
| -rwxr-xr-x | challenge-128/stuart-little/python/ch-2.py | 16 |
2 files changed, 35 insertions, 0 deletions
diff --git a/challenge-128/stuart-little/python/ch-1.py b/challenge-128/stuart-little/python/ch-1.py new file mode 100755 index 0000000000..df2409ac3e --- /dev/null +++ b/challenge-128/stuart-little/python/ch-1.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python + +# run <script> <space-separated binary words, with one word representing each row> + +from functools import reduce +import re +import sys + +rows,cols=0,0 + +def mrg(s1,s2): + return f"{int(bin(int(s1,2) | int(s2,2))[2:]):0{len(s1)}d}" + +for (i,j) in [(i,j) for i in range(len(sys.argv[1:])) for j in range(i,len(sys.argv[1:]))]: + mx=max(re.split(r"[^0]+",reduce(mrg,sys.argv[1+i:2+j])), key=len) + if (j-i+1)*len(mx) > rows*cols: + rows,cols=j-i+1,len(mx) + +print("\n".join(['0' * cols] * rows)) diff --git a/challenge-128/stuart-little/python/ch-2.py b/challenge-128/stuart-little/python/ch-2.py new file mode 100755 index 0000000000..f98f1511c2 --- /dev/null +++ b/challenge-128/stuart-little/python/ch-2.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python + +# run <script> <starting arrivals followed by departures, all space-separated> + +import sys + +times = sorted([ (x,y % (len(sys.argv[1:])//2)) for (x,y) in zip(sys.argv[1:], range(len(sys.argv[1:])))], key=lambda x: x[0]) +sol=0 +station=[0] * (len(sys.argv[1:])//2) + +for tm in times: + station[tm[1]]^=1 + if sum(station) > sol: + sol = sum(station) + +print(sol) |
