Skip to content

Commit

Permalink
Add solution for day 6
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Hessner committed Dec 6, 2017
1 parent e8f30e8 commit 55cffc7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions day6/input
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5 1 10 0 1 7 13 14 3 12 8 10 7 12 0 6
30 changes: 30 additions & 0 deletions day6/solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/python3

# http://adventofcode.com/2017/day/6

with open("input") as inputfile:
lines = inputfile.read().splitlines()
blocks = [int(x) for x in lines[0].split("\t")]

seen_blocks = []

n = len(blocks)

while blocks not in seen_blocks:
# Important: Convert to list in order to force a copy instead of a reference
seen_blocks.append(list(blocks))

v = max(blocks)
i = blocks.index(v)

# Redistribute block value
blocks[i] = 0
for j in range(v):
blocks[(i+j+1) % n] += 1


cycles = len(seen_blocks)
firstcycle = seen_blocks.index(blocks)

print("part 1", cycles)
print("part 2", cycles-firstcycle)

0 comments on commit 55cffc7

Please sign in to comment.