aoc2024/lib/aoc.py

26 lines
734 B
Python

import re
def nums(s:str) -> list[int]:
return list(map(int,re.findall(r'-?\d+',s)))
TESTS = [
("", []),
("9738: 7 89 52 75 8 1", [9738, 7, 89, 52, 75, 8, 1]),
("p=62,20 v=85,-14", [62, 20, 85, -14]),
("24 25 28 31 28", [24, 25, 28, 31, 28]),
("how():mul(422,702)'how()'", [422,702]),
("58692 56129", [58692, 56129]),
("Button A: X+16, Y+32", [16, 32]),
("46,51,67,25,72,77,13,96,36,76,52,23", [46,51,67,25,72,77,13,96,36,76,52,23]),
("47|53", [47,53]),
("..........M..........j.............y.....O........", []),
]
if __name__ == "__main__":
for (q,a) in TESTS:
assert nums(q) == a
a, b = nums("how():mul(422,702)'how()'")
assert a == 422
assert b == 702