started day4
This commit is contained in:
1 parent
2cd5a8f9fd
commit
10a0971346
2 files changed
+49
No files matched your search
@@ -0,0 +1,39 @@
|
||||
import sys
|
||||
|
||||
with open('test.text', 'r') as file:
|
||||
data: list[str] = file.readlines()
|
||||
|
||||
y_bound = len(data)
|
||||
x_bound = len(data[0])
|
||||
|
||||
# Part 1
|
||||
def search_all_directions(s: str, x: int, y: int):
|
||||
print(s)
|
||||
if s != 'X' and s != 'XM' and s != 'XMA' and s != 'XMAS':
|
||||
return 0
|
||||
|
||||
if x < 0 or y < 0 or x >= x_bound or y >= y_bound:
|
||||
return 0
|
||||
|
||||
# print(x, y)
|
||||
if data[y][x] != s:
|
||||
s = s + data[y][x]
|
||||
print(s)
|
||||
|
||||
if s == 'XMAS':
|
||||
return 1
|
||||
|
||||
return (search_all_directions(s, y, x - 1)
|
||||
+ search_all_directions(s, y, x + 1)
|
||||
+ search_all_directions(s, y + 1, x)
|
||||
+ search_all_directions(s, y - 1, x)
|
||||
)
|
||||
|
||||
total = 0
|
||||
for y, line in enumerate(data):
|
||||
for x, char in enumerate(line):
|
||||
if char == 'X':
|
||||
total += search_all_directions(char, x, y)
|
||||
|
||||
print(total)
|
||||
|
||||
Reference in new issue
Block a user