Added solution for day 4
This commit is contained in:
parent
6cf6f5bf02
commit
97e4aafa98
4 changed files with 244 additions and 0 deletions
10
day4/example.txt
Normal file
10
day4/example.txt
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
MMMSXXMASM
|
||||||
|
MSAMXMSMSA
|
||||||
|
AMXSXMAAMM
|
||||||
|
MSAMASMSMX
|
||||||
|
XMASAMXAMM
|
||||||
|
XXAMMXXAMA
|
||||||
|
SMSMSASXSS
|
||||||
|
SAXAMASAAA
|
||||||
|
MAMMMXMMMM
|
||||||
|
MXMXAXMASX
|
140
day4/input.txt
Normal file
140
day4/input.txt
Normal file
|
@ -0,0 +1,140 @@
|
||||||
|
SAMXXSXXSXSAMXMMSMMMMSAMXSXMMMAMXXMSSMSMMMMMXSAXMAMMSSMXMXMAXSXSASMSSMXMMSAMXMMXMMSSSMMMSAMXXSASMSAMXMSXXAMAMXMMXMSAMXSMSMSXSMAMXMASXMXAMSMM
|
||||||
|
MAMMXSMMMAASMMMASAAAAXAMASXMASMMSSMAMAASAASXMMMMSAMXAAAAMMMSAXXMASXAAASAAXMXASMXSAXMASAAMMSXMXAMASXXAMXXMMSAMXXXAMXXMXXAXAAAXSMXMAMMAMSAMAAX
|
||||||
|
SAMXAXAAMAMMSXMASXMMMXAMASASASAAAAMMSSMSMMXAXAAAMASMSSMMXAAXMSAMXMMSMMAMMXAMXXAAMMXSAMMMMAMASMSMAMXMSSMAMAAAXXMSMSAXXAMXMMMSMAXSSMMSAMMASXSM
|
||||||
|
SSSMXMXSXAMXAXMXXMMAMSMMXSAMASMMSSMXAAXSXMSMMMMSSMMAAXMAMMSMMXMASMAXAAMSSXMSMSMMMXXMAMSXMASMMAAMAMMAAAXMMSSMMAAAXMMSMXMASXAMMMMMAAMSASMXMAXA
|
||||||
|
SAMXMSMMXMSMMMMSMMMAMAXSMSXSXSXAXXXMSSMMAXAAAMAAAAMSMMMSAXAAXMMAAMXSAMXAXAAXAASXXMMSSMAMSAMAMSMSXSAMSMMMAA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ASMXMXMAMMMMMXMASAMAXMXMMAXSASASMMSMMASASAMMMSAMASXMSMMXSMMMASXMXSSXMXSAAAASAMAMSMAMXSXAAAAX
|
||||||
|
SSMMMSAMSMSAMMSMMMXSAMXXAMXSSSMMMSSXMASXMXMXMXXSXSMSXAMAMAMASAMXSASXMMMSXMMMXMAMMAAAXMMXXAMXXMAXXAMASAMAXASMSMASAMXMMMSMSMSMAMXMAAXMASMSMMMM
|
||||||
|
SAAXMMAMAASXMAAMASAMASAMSSXMXAAAAXAXXMASMAMSMSXSXMAMMAXMXXXAMAMXSAMMXXASASXSMMXMMSXSMXXMSMMMSSSMMAMASAMASXXXMSAMASAMAAXXAXMXXMSMMSSMXSAMXMAS
|
||||||
|
SMMMMSXSMXMMMSASAMXSAMAMAAAMSSSMMSMMMMMMSMXAAMASXMAMSMSXSSMMSAMMMMMMMSMSAMAMAMAMXAMXAMXMAMXAAAXXSAMMSAMAMAXMMMMSAMXMMSSSSSSMSXAAXAXXAMMMAMXM
|
||||||
|
MAAAASMXXSAMXAAXMAXMXSAMXSMMAXMAXAXAASAAAXSMAMAMASXXSASAAMAMSXMXAXMAAXAMMMAMSMASMASMAXXSASAMMSMMSXSMSXMASXAMAAMMASMSXMAXAAAAXSSSMXSMXSXSXMAX
|
||||||
|
SMSMSSMXMASASMSMMXXMASMMXXAXXSSMSASMSSMSSMSSXMASMMXAMAMMMMAMMMSSXMXMSSXMXMASMMXSXXMMXMASXSXAXAMMXMAXMASXXAXXSSSMXXMASAMXMSMMMAXXMASMSAMXASMS
|
49
day4/solution.py
Normal file
49
day4/solution.py
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
def read_grid(filename):
|
||||||
|
grid = []
|
||||||
|
with open(filename, 'r') as file:
|
||||||
|
for line in file:
|
||||||
|
grid.append(list(line.strip()))
|
||||||
|
return grid
|
||||||
|
|
||||||
|
def count_word_occurrences(grid, word):
|
||||||
|
rows = len(grid)
|
||||||
|
cols = len(grid[0])
|
||||||
|
word_length = len(word)
|
||||||
|
count = 0
|
||||||
|
|
||||||
|
directions = [
|
||||||
|
(0, 1), # Right
|
||||||
|
(1, 0), # Down
|
||||||
|
(0, -1), # Left
|
||||||
|
(-1, 0), # Up
|
||||||
|
(1, 1), # Diagonal down-right
|
||||||
|
(1, -1), # Diagonal down-left
|
||||||
|
(-1, -1), # Diagonal up-left
|
||||||
|
(-1, 1), # Diagonal up-right
|
||||||
|
]
|
||||||
|
|
||||||
|
for x in range(rows):
|
||||||
|
for y in range(cols):
|
||||||
|
for dx, dy in directions:
|
||||||
|
match = True
|
||||||
|
for k in range(word_length):
|
||||||
|
nx = x + dx * k
|
||||||
|
ny = y + dy * k
|
||||||
|
if 0 <= nx < rows and 0 <= ny < cols:
|
||||||
|
if grid[nx][ny] != word[k]:
|
||||||
|
match = False
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
match = False
|
||||||
|
break
|
||||||
|
if match:
|
||||||
|
count += 1
|
||||||
|
return count
|
||||||
|
|
||||||
|
# Main execution
|
||||||
|
if __name__ == "__main__":
|
||||||
|
grid = read_grid('input.txt')
|
||||||
|
# grid = read_grid('example.txt')
|
||||||
|
word = "XMAS"
|
||||||
|
total_occurrences = count_word_occurrences(grid, word)
|
||||||
|
print(total_occurrences)
|
45
day4/solution2.py
Normal file
45
day4/solution2.py
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
def read_grid(filename):
|
||||||
|
grid = []
|
||||||
|
with open(filename, 'r') as file:
|
||||||
|
for line in file:
|
||||||
|
grid.append(list(line.strip()))
|
||||||
|
return grid
|
||||||
|
|
||||||
|
# Function to check if a diagonal forms 'MAS' or 'SAM'
|
||||||
|
def check_diagonal(grid, x, y, dx, dy):
|
||||||
|
rows = len(grid)
|
||||||
|
cols = len(grid[0])
|
||||||
|
letters = []
|
||||||
|
for k in range(-1, 2): # Positions: -1, 0, 1
|
||||||
|
nx = x + dx * k
|
||||||
|
ny = y + dy * k
|
||||||
|
if 0 <= nx < rows and 0 <= ny < cols:
|
||||||
|
letters.append(grid[nx][ny])
|
||||||
|
else:
|
||||||
|
return False # Out of bounds
|
||||||
|
word = ''.join(letters)
|
||||||
|
return word == 'MAS' or word == 'SAM'
|
||||||
|
|
||||||
|
def count_xmas_patterns(grid):
|
||||||
|
rows = len(grid)
|
||||||
|
cols = len(grid[0])
|
||||||
|
count = 0
|
||||||
|
|
||||||
|
for x in range(1, rows - 1):
|
||||||
|
for y in range(1, cols - 1):
|
||||||
|
if grid[x][y] != 'A':
|
||||||
|
continue
|
||||||
|
diagonal1 = check_diagonal(grid, x, y, -1, -1) # Top-left to bottom-right
|
||||||
|
diagonal2 = check_diagonal(grid, x, y, -1, 1) # Top-right to bottom-left
|
||||||
|
|
||||||
|
if diagonal1 and diagonal2:
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
return count
|
||||||
|
|
||||||
|
# Main execution
|
||||||
|
if __name__ == "__main__":
|
||||||
|
grid = read_grid('input.txt')
|
||||||
|
# grid = read_grid('example.txt')
|
||||||
|
total_xmas = count_xmas_patterns(grid)
|
||||||
|
print(total_xmas)
|
Loading…
Reference in a new issue