Skip to content

Commit

Permalink
2016 day 16 solutions
Browse files Browse the repository at this point in the history
Signed-off-by: Lance-Drane <ldraneutk@gmail.com>
  • Loading branch information
Lance-Drane committed Jan 5, 2024
1 parent 8167859 commit 776425b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
17 changes: 17 additions & 0 deletions 2016/16/1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def flip_bits(binary_str: str):
inverse = int(binary_str, 2) ^ (2 ** (len(binary_str) + 1) - 1)
return bin(inverse)[3:]


TARGET_LENGTH = 272

data = input()
while len(data) < TARGET_LENGTH:
data = f'{data}0{flip_bits(data[::-1])}'
data = data[:TARGET_LENGTH]

while len(data) & 1 != 1:
# in python 3.12, can potentially use itertools.batched instead
data = ['1' if chunk[0] == chunk[1] else '0' for chunk in zip(*[iter(data)] * 2, strict=False)]

print(''.join(data))
1 change: 1 addition & 0 deletions 2016/16/1_out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10100011010101011
17 changes: 17 additions & 0 deletions 2016/16/2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def flip_bits(binary_str: str):
inverse = int(binary_str, 2) ^ (2 ** (len(binary_str) + 1) - 1)
return bin(inverse)[3:]


TARGET_LENGTH = 35651584

data = input()
while len(data) < TARGET_LENGTH:
data = f'{data}0{flip_bits(data[::-1])}'
data = data[:TARGET_LENGTH]

while len(data) & 1 != 1:
# in python 3.12, can potentially use itertools.batched instead
data = ['1' if chunk[0] == chunk[1] else '0' for chunk in zip(*[iter(data)] * 2, strict=False)]

print(''.join(data))
1 change: 1 addition & 0 deletions 2016/16/2_out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
01010001101011001
1 change: 1 addition & 0 deletions 2016/16/in.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11100010111110100

0 comments on commit 776425b

Please sign in to comment.