From b52eef5b9399ab3888fcfe1bc9ca23c7a9f7b026 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Wed, 10 Dec 2025 18:15:14 +0100 Subject: Day 10 2025 --- 2025/10/a.py | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to '2025/10/a.py') diff --git a/2025/10/a.py b/2025/10/a.py index 5fdb11b..52fa0b0 100644 --- a/2025/10/a.py +++ b/2025/10/a.py @@ -1,6 +1,37 @@ import fileinput +def readline(line): + m = 0 + for i in range(1, line.index(']')): + if line[i] == '#': + m |= 1 << (i-1) + + b = [] + j = line.index(']') + while '(' in line[j:]: + i = line[j:].index('(') + j + 1 + j = line[i:].index(')') + i + x = 0 + for y in line[i:j].split(','): + x |= 1 << int(y) + b.append(x) + + return m, b + +def works(m, b, s): + x = 0 + for j in range(len(s)): + if s[j] == '1': + x ^= b[j] + return x == m + +def sol(m, b): + s = 99999999 + for i in range(2**len(b)): + if works(m, b, bin(i)[2:].rjust(len(b), '0')): + s = min(s, i.bit_count()) + return s + with fileinput.input() as lines: - for line in lines: - ... + print(sum(sol(*readline(line)) for line in lines)) -- cgit v1.3