Skip to content

Commit

Permalink
Day 16
Browse files Browse the repository at this point in the history
  • Loading branch information
Theresa authored and Theresa committed Apr 12, 2020
1 parent 990c434 commit ea7e222
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion advent_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,5 +395,5 @@ def md5_increment(salt):

if __name__ == '__main__':
# start_coding_today()
today = 15
today = 16
start_coding(today)
44 changes: 44 additions & 0 deletions day16/day16.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import contextlib
import collections
import copy
import functools
import itertools
import numpy as np
import pandas as pd
import re

import advent_tools


def calc_checksum(start_data, needed_length):
data = make_right_length(start_data, needed_length)
while len(data) and len(data) % 2 == 0:
print(len(data))
new_data = ''
for first, second in zip(data[0::2], data[1::2]):
if first == second:
new_data = new_data + '1'
else:
new_data = new_data + '0'
data = new_data
return data

def make_right_length(start_data, needed_length):
data = start_data
while len(data) < needed_length:
rev = ''.join(['1' if a == '0' else '0' for a in reversed(data)])
data = data + '0' + rev
return data[:needed_length]


def run_part_1():
print(calc_checksum('11110010111001001', 272))


def run_part_2():
print(calc_checksum('11110010111001001', 35651584))


if __name__ == '__main__':
run_part_1()
run_part_2()
1 change: 1 addition & 0 deletions day16/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11110010111001001

0 comments on commit ea7e222

Please sign in to comment.