示例#1
0
    if command == 'down':
        return (state[0], state[1] + distance)


state = (0, 0)  # horizontal, depth
for action in data:
    state = handle_action(action, state)

# SOLUTION 2


def handle_action2(action, state):
    command = action[0]
    distance = int(action[1])

    if command == 'forward':
        return (state[0] + distance, state[1] + (state[2] * distance),
                state[2])
    if command == 'up':
        return (state[0], state[1], state[2] - distance)
    if command == 'down':
        return (state[0], state[1], state[2] + distance)


state2 = (0, 0, 0)  # horizontal, depth, aim
for action in data:
    state2 = handle_action2(action, state2)

# WRITE
write_output([str(state[0] * state[1]), str(state2[0] * state2[1])])
示例#2
0
        m[polymer] += 1
        total[template[i]] += 1
    return m, total


def growPolymerCount(counter, total):
    m = defaultdict(int)
    for polymer, c in counter.items():
        newNode = rules[polymer]
        m[polymer[0] + newNode] += c
        m[newNode + polymer[1]] += c
        total[newNode] += c
    return m


def growPolymer2(counter, total, steps):
    i = 0
    while i < steps:
        counter = growPolymerCount(counter, total)
        i += 1
    return total


counter, total = initPolymerCount(polymerTemplate)
total = growPolymer2(counter, total, 40)
values = [v for v in total.values()]
solution_2 = max(values) - min(values)

# WRITE
write_output([str(solution_1), str(solution_2)])
示例#3
0
from data_handler import write_input, write_output  # noqa

DAY = '24'
'''
1	1	12	7			
2	1	11	15			
3	1	12	2			
4	26	-3	15	3	2	D3-1=D4
5	1	10	14			
6	26	-9	2	5	14	D5+5=D6
7	1	10	15			
8	26	-7	1	7	15	D7+8=D8
9	26	-11	15	2	15	D2+4=D9
10	26	-4	15	1	7	D1+3=D10
11	1	14	12			
12	1	11	2			
13	26	-8	13	12	2	D12-6=D13
14	26	-10	13	11	12	D11+2=D14

D3-1=D4  	..21.......... ..98..........
D5+5=D6	    ..2116........ ..9849........
D7+8=D8	    ..211619...... ..984919......
D2+4=D9	    .12116195..... .59849199.....
D1+3=D10	1121161954.... 6598491999....
D12-6=D13	112116195471.. 659849199993..
D11+2=D14	11211619541713 65984919997939
'''

# WRITE
write_output([str(65984919997939), str(11211619541713)])