Skip to content

Commit

Permalink
Day 6 Completed
Browse files Browse the repository at this point in the history
  • Loading branch information
SpawnTerror committed Dec 25, 2022
1 parent 90d9a2c commit 670fcf4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
19 changes: 11 additions & 8 deletions day6/part2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,53 @@
# AOC Day 6 Part 2

# Working with 14 letters in a row

setSize = 14

# Grab each letter and put into a list

def getData(fileName: str) -> list:
with open(fileName, 'r') as f:
initialData = [x for x in f.readline()]
return initialData

# Part 2

def processData(data: list):

# Create dictionary to count occurences
# Marker is already on 14 as first set is 14 long

dictionarySet = {}
markerPosition = 14

# Itterate through every letter
# (-3) to end on a full set of 14
# Put 14 letters into a line

for x in range(0, len(data)-3):
dictionarySet = {}
line = data[x: x + setSize]

# Count occurences of each letter
# in the current dictionary of 14

for letter in line:
if letter in dictionarySet:
dictionarySet[letter] += 1
else:
dictionarySet[letter] =1

# Check if all counts are equal to 1
# If true, return the set and marker position
# As letters are added as keys
# and duplicates are merged
# Stop when we count to 14
# which means all letters are unique

if len(dictionarySet) == 14:
return dictionarySet, markerPosition
else:
markerPosition += 1
'''
if all(value == 1 for value in dictionarySet.values()):
return dictionarySet, markerPosition
else:
markerPosition += 1
'''

data = getData('day6/input.txt')
uniqueSet, markerPosition = processData(data)

Expand Down
Empty file added day7/input.txt
Empty file.
3 changes: 3 additions & 0 deletions day7/part1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SpawnTerror 2022
# Python 3.11.1
# AOC Day 7 Part 1
3 changes: 3 additions & 0 deletions day7/part2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SpawnTerror 2022
# Python 3.11.1
# AOC Day 7 Part 2
Empty file added day7/test.txt
Empty file.

0 comments on commit 670fcf4

Please sign in to comment.