Exemple #1
0
def day_16_2(dance_moves):
    dance = lambda line: reduce(apply_dance_move, dance_moves, line)
    cycle_length, cycle_start = floyd(dance, initial_line)

    # Exact minimum number of dances required to reach the final state
    dance_count = cycle_start + (dance_repeat_count -
                                 cycle_start) % cycle_length
    final_line = apply_n(dance, dance_count, initial_line)

    return ''.join(final_line)
Exemple #2
0
def day_10_2(raw_lengths):
    lengths = [ord(c) for c in raw_lengths] + lengths_suffix

    apply_round = lambda k: knot_hash_round(lengths, k)
    final_knot = apply_n(apply_round, round_count, Knot())

    sparse_hash = final_knot.marks
    dense_hash = (reduce(xor, sparse_hash[i:i + block_size])
                  for i in range(0, knot_size, block_size))
    final_hash = ''.join(format(n, '02x') for n in dense_hash)

    return final_hash
Exemple #3
0
def day_22_2(cluster_center):
    initial_state = cluster_state(cluster_center)
    burst_p2 = lambda state: burst(state, NODE_TRANSITIONS_P2)
    final_virus, _ = apply_n(burst_p2, 10000000, initial_state)

    return final_virus.infected_count