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.
I'm not super familiar with what programming language you're using but "set" is a data structure with unique keys, right? and if you stick four characters in a set and any are dupes, the size of the container will be less than 4 (or 14)? Honestly I had that idea too at first but didn't know off the top of my head how to do that in C++ and I figured a dumbass manually-check-each-character algorithm would take my brain less time to understand. I like your answer a lot.
Current HP: 8/75
Current Mana: 130/250
Inventory:
* 50 Gald
Jump in the discussion.
No email address required.
yeah, sets in python are basically just an unordered collection with no duplicates that have methods like intersection(), union() and issuperset() that are supposed to be analagous to operations on sets in mathematics. they have been pretty useful so far for AoC - used them for days 3 and 4 also.
Jump in the discussion.
No email address required.
More options
Context
More options
Context