Unable to load image

Advent of code day 4 :marseysad:

This is the advent of code day 4 thread for bragging about your solution and bullying people who haven't gotten it yet :marseyill:

35
Jump in the discussion.

No email address required.

Solution with no comparisons, only bitflips and abuse of casting :marseytroll:

def to_unary(number):
    to_return = 0
    for i in range(int(number)):
        to_return+=2**i
    return to_return

# PART 2 BITWISE
matcher = re.compile(R"([0-9]*)-([0-9]*),([0-9]*)-([0-9]*)")
score = 0
for pair in lines:
    result = matcher.search(pair)
    a_min = to_unary(result.group(1))
    a_max = to_unary(result.group(2))
    b_min = to_unary(result.group(3))
    b_max = to_unary(result.group(4))
    #print(f"A MIN: {a_min:b} A MAX: {a_max:b} B MIN: {b_min:b} B MAX: {b_max:b}")
    
    score+=int(bool(((a_max ^ a_min) | ((a_min+1) >> 1)) & ((b_max ^ b_min) | ((b_min+1) >> 1))))
Jump in the discussion.

No email address required.

Please keep yourself safe

Jump in the discussion.

No email address required.

Why?

Jump in the discussion.

No email address required.

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.