You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
831 B

import re
import sys
def get_xy(line):
xmatch = re.search(r"X(\d*)", line)
ymatch = re.search(r"Y(\d*)", line)
if xmatch is None or ymatch is None:
return None, None
xval = int(xmatch.group().strip("X"))
yval = int(ymatch.group().strip("Y"))
return xval, yval
def parse_file(fname):
with open(fname) as fp:
lines = fp.read().splitlines()
minx = float('inf')
miny = float('inf')
maxx = float('-inf')
maxy = float('-inf')
for line in lines:
x, y = get_xy(line)
if x is None or y is None:
continue
minx = min(x, minx)
maxx = max(x, maxx)
miny = min(y, miny)
maxy = max(y, maxy)
print(f"MinX={minx}, MinY={miny}, MaxX={maxx}, MaxY={maxy}")
if __name__ == '__main__':
parse_file(sys.argv[1])