Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def day18(s, *, part2=False):
- x = 0
- area = 1
- for line in s.splitlines():
- op, s_num, color = re.match(r'^([LRUD]) (\d+) \(#(......)\)$', line).groups()
- num = int(color[:5], 16) if part2 else int(s_num)
- op = 'RDLU'[int(color[5])] if part2 else op
- match op:
- case 'R':
- x += num
- area += num
- case 'L':
- x -= num
- case 'D':
- area += x * num + num
- case 'U':
- area -= x * num
- return area
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement