Skip to content

Latest commit

 

History

History
79 lines (58 loc) · 1.89 KB

20.md

File metadata and controls

79 lines (58 loc) · 1.89 KB

Day 20

Part 1 Part 2 Total
Time 1:52:18 2:02 1:54:20

Part 1

Part 1 took me embarrassingly long. The VERY first thing I did was loop through the input and check if their were duplicate entries, and my code said that there weren't any. I guess I just did it wrong? I had the smart solution in 5-ish minutes, but the stupid duplicate numbers threw everything off as you can see by how I was finding the elements. At about 1:50AM as a last-ditch effort, I pasted the input into an online duplicate line checker tool and just about screamed!

from helpers.datagetter import data_in, submit

ans = 0
din = data_in(split=True, numbers=True)

nums = []
offset = 0

for x in din:
    num = str(x[0] * mult)
    if str(x[0] * mult) in nums:
        nums.append(f"{num}.{offset}")
        offset += 1
    else:
        nums.append(num)

orig_nums = nums.copy()

for num in orig_nums:
    idx = nums.index(num)
    nums.pop(idx)
    nums.insert((idx + int(num.split(".")[0])) % len(nums), num)

for i in range(1, 4):
    t = nums[(nums.index('0') + (1000 * i)) % len(orig_nums)].split(".")[0]
    ans += int(t)

print(ans)
submit(ans)

Part 2

Once I had Part 1, Part 2 was very simple due to how I move the elements around (modulus).

from helpers.datagetter import data_in, submit

ans = 0
din = data_in(split=True, numbers=True)

nums = []
offset = 0
mult = 811589153

for x in din:
    num = str(x[0] * mult)
    if str(x[0] * mult) in nums:
        nums.append(f"{num}.{offset}")
        offset += 1
    else:
        nums.append(num)

orig_nums = nums.copy()

for _ in range(10):
    for num in orig_nums:
        idx = nums.index(num)
        nums.pop(idx)
        nums.insert((idx + int(num.split(".")[0])) % len(nums), num)

for i in range(1, 4):
    t = nums[(nums.index('0') + (1000 * i)) % len(orig_nums)].split(".")[0]
    ans += int(t)

print(ans)
submit(ans)