Created
December 9, 2018 12:58
-
-
Save ErikThorsell/d60f73154c0b53944c4f46bc0c3932c3 to your computer and use it in GitHub Desktop.
Day 9, AoC 2018
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def task_1(players=9, last_marble_point=25): | |
scores = [0] * players | |
circle = [0] | |
p = 0 | |
marble = 0 | |
current_marble_idx = 0 | |
while marble < last_marble_point: | |
p = (p + 1) % players | |
marble += 1 | |
insert_at = (current_marble_idx + 2) % len(circle) | |
if marble % 23 == 0: | |
current_marble_idx = (insert_at - 9) % len(circle) | |
score = marble | |
score += circle.pop(current_marble_idx) | |
scores[p] += score | |
else: | |
circle.insert(insert_at, marble) | |
current_marble_idx = insert_at | |
return(max(scores)) | |
def task_2(players=9, last_marble_point=25): | |
scores = [0] * players | |
circle = deque() | |
circle.insert(0, 0) | |
p = 0 | |
marble = 0 | |
while marble < last_marble_point: | |
p = (p + 1) % players | |
marble += 1 | |
if marble % 23 == 0: | |
circle.rotate(-7) | |
score = marble | |
score += circle.pop() | |
scores[p] += score | |
else: | |
circle.rotate(2) | |
circle.append(marble) | |
return(max(scores)) | |
## MAIN ## | |
if __name__ == "__main__": | |
data = get_input(9) | |
print(f"a: {task_1(data[0], data[1])}") | |
print(f"b: {task_2(data[0], data[1]*100)}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment