initial commit, day 10
This commit is contained in:
42
04b.py
Executable file
42
04b.py
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
with open('04a.txt') as f:
|
||||
lines = f.readlines()
|
||||
lines = [x.strip() for x in lines if x.strip()]
|
||||
count = 0
|
||||
|
||||
i_len = len(lines)
|
||||
j_len = len(lines[0])
|
||||
for i in range(i_len):
|
||||
for j in range(j_len):
|
||||
if lines[i][j] == 'X':
|
||||
UP = i >= 3
|
||||
DOWN = (i_len - i) >= 4
|
||||
LEFT = j >= 3
|
||||
RIGHT = (j_len - j) >= 4
|
||||
if UP:
|
||||
if lines[i-1][j] == 'M' and lines[i-2][j] == 'A' and lines[i-3][j] == 'S':
|
||||
count += 1
|
||||
if DOWN:
|
||||
if lines[i+1][j] == 'M' and lines[i+2][j] == 'A' and lines[i+3][j] == 'S':
|
||||
count += 1
|
||||
if LEFT:
|
||||
if lines[i][j-1] == 'M' and lines[i][j-2] == 'A' and lines[i][j-3] == 'S':
|
||||
count += 1
|
||||
if RIGHT:
|
||||
if lines[i][j+1] == 'M' and lines[i][j+2] == 'A' and lines[i][j+3] == 'S':
|
||||
count += 1
|
||||
if UP and LEFT:
|
||||
if lines[i-1][j-1] == 'M' and lines[i-2][j-2] == 'A' and lines[i-3][j-3] == 'S':
|
||||
count += 1
|
||||
if UP and RIGHT:
|
||||
if lines[i-1][j+1] == 'M' and lines[i-2][j+2] == 'A' and lines[i-3][j+3] == 'S':
|
||||
count += 1
|
||||
if DOWN and LEFT:
|
||||
if lines[i+1][j-1] == 'M' and lines[i+2][j-2] == 'A' and lines[i+3][j-3] == 'S':
|
||||
count += 1
|
||||
if DOWN and RIGHT:
|
||||
if lines[i+1][j+1] == 'M' and lines[i+2][j+2] == 'A' and lines[i+3][j+3] == 'S':
|
||||
count += 1
|
||||
|
||||
print(count)
|
||||
Reference in New Issue
Block a user