mirror of
https://github.com/cupcakearmy/advent-of-code.git
synced 2024-12-21 15:46:28 +00:00
6
This commit is contained in:
parent
fd990ec256
commit
bf613c4583
11
2022/06/README.md
Normal file
11
2022/06/README.md
Normal file
@ -0,0 +1,11 @@
|
||||
# 06
|
||||
|
||||
Mhh. Don't know why this was day 6. It was a 2 minute thing, a lot easier than the days before.
|
||||
|
||||
<details>
|
||||
<summary>Solutions</summary>
|
||||
<ol>
|
||||
<li>1912</li>
|
||||
<li>2122</li>
|
||||
</ol>
|
||||
</details>
|
37
2022/06/python/main.py
Normal file
37
2022/06/python/main.py
Normal file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from dataclasses import dataclass
|
||||
from os.path import dirname, join
|
||||
|
||||
# Day 06
|
||||
|
||||
# Common
|
||||
|
||||
|
||||
def read_input(filename):
|
||||
data = join(dirname(__file__), '..', filename)
|
||||
with open(data) as f:
|
||||
return f.read().strip()
|
||||
|
||||
|
||||
test = read_input('test.txt')
|
||||
data = read_input('input.txt')
|
||||
|
||||
|
||||
def find_marker(buffer, size=4) -> int:
|
||||
for i in range(len(buffer)):
|
||||
subset = buffer[i:i+size]
|
||||
if len(subset) == len(set(subset)):
|
||||
return i + size
|
||||
return -1
|
||||
|
||||
|
||||
# 1
|
||||
print('1.')
|
||||
print(find_marker(test))
|
||||
print(find_marker(data))
|
||||
|
||||
# 2
|
||||
print('\n2.')
|
||||
print(find_marker(test, size=14))
|
||||
print(find_marker(data, size=14))
|
Loading…
Reference in New Issue
Block a user