diff --git a/day-14/01.py b/day-14/01.py new file mode 100644 index 0000000..684b598 --- /dev/null +++ b/day-14/01.py @@ -0,0 +1,31 @@ +state = [3, 7] + +puzzle_in = 77201 + +elf_1 = 0 +elf_2 = 1 + +def print_state(): + out = '' + for i, el in enumerate(state): + if i == elf_1: + out += '(' + str(el) + ')' + elif i == elf_2: + out += '[' + str(el) + ']' + else: + out += ' ' + str(el) + ' ' + print(out) + +while len(state) < puzzle_in + 10: + val_1 = state[elf_1] + val_2 = state[elf_2] + + state.extend([ int(x) for x in list(str(val_1 + val_2)) ]) + + elf_1 = (1 + elf_1 + val_1) % len(state) + elf_2 = (1 + elf_2 + val_2) % len(state) + + # print_state() + +print(''.join([str(x) for x in state[puzzle_in:puzzle_in + 10]])) + diff --git a/day-14/02.py b/day-14/02.py new file mode 100644 index 0000000..28f97c7 --- /dev/null +++ b/day-14/02.py @@ -0,0 +1,43 @@ +state = [3, 7] + +puzzle_in = '077201' + +elf_1 = 0 +elf_2 = 1 + +def print_state(): + out = '' + for i, el in enumerate(state): + if i == elf_1: + out += '(' + str(el) + ')' + elif i == elf_2: + out += '[' + str(el) + ']' + else: + out += ' ' + str(el) + ' ' + print(out) + +while 1: + val_1 = state[elf_1] + val_2 = state[elf_2] + + state.extend([ int(x) for x in list(str(val_1 + val_2)) ]) + + test_1 = state[-6:] + test_2 = state[-7:-1] + + # print(''.join([str(x) for x in test_1]), ''.join([str(x) for x in test_2]), puzzle_in) + + if ''.join([str(x) for x in test_1]) == puzzle_in: + res = len(state) - 6 + break + + if ''.join([str(x) for x in test_2]) == puzzle_in: + res = len(state) - 7 + break + + elf_1 = (1 + elf_1 + val_1) % len(state) + elf_2 = (1 + elf_2 + val_2) % len(state) + + # print_state() + +print(res)