was preparing my butthole after the last one but ended up being the fastest one i've done
with open("day6input.txt") as f:
input = f.read()
# part 1
for i in range(len(input)):
marker = set(input[i:i+4])
if len(marker) == 4:
answer = i + 4
break
print(answer)
# part 2
for i in range(len(input)):
marker = set(input[i:i+14])
if len(marker) == 14:
answer = i + 14
break
print(answer)
Jump in the discussion.
No email address required.
c++
spent some time to find a O(1) for adding and checking if string is unique and then just gave up and ended up on O(n), with n being the length of the substring
Jump in the discussion.
No email address required.
Sorry ma'am, looks like his delusions have gotten worse. We'll have to admit him.
Jump in the discussion.
No email address required.
More options
Context
Okay here is the O(1) version for checking if string is unique
The first version ran in(without reading from the file):
Part One: 1109 Time: 24us
Part Two: 3965 Time: 62us
The second version in:
Part One: 1109 Time: 3us
Part Two: 3965 Time: 8us
Jump in the discussion.
No email address required.
No, don't reply like this, please do another wall of unhinged rant please.
Jump in the discussion.
No email address required.
More options
Context
More options
Context
More options
Context