diff --git a/23/1.py b/23/1.py new file mode 100644 index 0000000..20a0d78 --- /dev/null +++ b/23/1.py @@ -0,0 +1,27 @@ +content = [int(x) for x in "156794823"] +lowest = min(content) +highest = max(content) +original_length = len(content) +for turn in range(100): + print("--------------------") + print(f"turn {turn+1}") + print(content) + removed = content[1:4] + print(f"removed : {removed}") + del(content[1:4]) + content *= 2 + destination = content[0] - 1 + if destination < lowest: + destination = highest + while destination in removed: + destination -= 1 + if destination < lowest: + destination = highest + print(f"destination: {destination}") + destindex = content.index(destination) + 1 + content[destindex:destindex] = removed + content = content[1:1+original_length] + + +content *= 2 +print(content[content.index(1) + 1: content.index(1) + original_length]) diff --git a/23/2.py b/23/2.py new file mode 100644 index 0000000..5684ea3 --- /dev/null +++ b/23/2.py @@ -0,0 +1,38 @@ +def main(): + current = 0 + content = [int(x) for x in "156794823"] + highest = max(content) + for i in range(highest+1, 1000001): + content.append(i) + original_length = len(content) + lowest = min(content) + highest = max(content) + turn = 0 + while turn < 10000000: + removed1 = content[current + 1 % 1000000] + removed2 = content[current + 2 % 1000000] + removed3 = content[current + 3 % 1000000] + del(content[current + 1 % 1000000]) + del(content[current + 1 % 1000000]) + del(content[current + 1 % 1000000]) + destination = content[current] - 1 + if destination < lowest: + destination = highest + while destination == removed1 or destination == removed2 or destination == removed3: + destination -= 1 + if destination < lowest: + destination = highest + + destindex = content.index(destination) + destindex += 1 + content.insert(destindex, removed3) + content.insert(destindex, removed2) + content.insert(destindex, removed1) + current = current + 1 % 1000000 + turn += 1 + + + content *= 2 + print(content[content.index(1) + 1] * content[content.index(1) + 2]) + +main()