|
5 | 5 | """ Preprocessing Functions """ |
6 | 6 |
|
7 | 7 |
|
| 8 | +def _preprocess_vertical(string: str): |
| 9 | + """ """ |
| 10 | + |
| 11 | + tokens = re.split(r'\n(#(?: \S+)+\n(?: *\d\S*(?: +\S+)+\n)+)', string) |
| 12 | + |
| 13 | + string = '' |
| 14 | + for token in tokens: |
| 15 | + if (match := re.match(r'#((?: \S+)+)\n((?: *\d\S*(?: +\S+)+\n)+)', token)): |
| 16 | + cards = re.split(r'\s+', match[1])[1:] |
| 17 | + rows = [[card] for card in cards] |
| 18 | + |
| 19 | + lines = match[2].split('\n')[:-1] |
| 20 | + for line in lines: |
| 21 | + parameters = re.split(r'\s+', line) |
| 22 | + for parameter, row in zip(parameters, rows): |
| 23 | + row.append(parameter) |
| 24 | + |
| 25 | + string += '\n' + '\n'.join([' '.join(row) for row in rows]) + '\n' |
| 26 | + else: |
| 27 | + string += token |
| 28 | + |
| 29 | + return string |
| 30 | + |
8 | 31 | def _preprocess_horizontal(string: str): |
9 | 32 | """ """ |
10 | 33 |
|
11 | 34 | tokens = re.split(r'( \d+j)', string) |
12 | 35 |
|
13 | 36 | string = '' |
14 | | - for i, token in enumerate(tokens): |
| 37 | + for token in tokens: |
15 | 38 | if match := re.match(r'( \d+)j', token): |
16 | 39 | string += int(match[1]) * ' j' |
17 | 40 | else: |
@@ -71,6 +94,7 @@ def _preprocess_comments(string: str): |
71 | 94 | def preprocess_inp(string: str): |
72 | 95 | """ """ |
73 | 96 |
|
| 97 | + string = _preprocess_vertical(string) |
74 | 98 | string, comments = _preprocess_comments(string) |
75 | 99 | string = _preprocess_case(string) |
76 | 100 | string = _preprocess_whitespace(string) |
|
0 commit comments