diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-08-31 00:39:06 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-31 00:39:06 +0100 |
| commit | 42dfba4163bb20673ef668d0aea68b2cd2925146 (patch) | |
| tree | d20c6956d2d55fbc60468d8eae751a4af94837db | |
| parent | c1673fc2265c06f3d635f9781f9ca9b2bfa934ef (diff) | |
| parent | 407e008c75a97ab845ec21a7f63644bd0d746657 (diff) | |
| download | perlweeklychallenge-club-42dfba4163bb20673ef668d0aea68b2cd2925146.tar.gz perlweeklychallenge-club-42dfba4163bb20673ef668d0aea68b2cd2925146.tar.bz2 perlweeklychallenge-club-42dfba4163bb20673ef668d0aea68b2cd2925146.zip | |
Merge pull request #4824 from stuart-little/stuart-little_128_python
1st commit on 128_python
| -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) |
