Day 13
This commit is contained in:
1 parent
1240614f8a
commit
5c59e7b253
4 files changed
+1573
No files matched your search
Executable
+49
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import numpy as np
|
||||
|
||||
|
||||
def find_reflexion(pattern):
|
||||
for i in range(1, len(pattern)):
|
||||
reflexion = True
|
||||
for j in range(i):
|
||||
if (i+i-j-1) > (len(pattern)-1): continue
|
||||
if not np.array_equal(pattern[j], pattern[i+i-j-1]): reflexion = False
|
||||
if reflexion: return i
|
||||
return 0
|
||||
|
||||
|
||||
def find_smudged_reflexion(pattern):
|
||||
for i in range(1, len(pattern)):
|
||||
smudges = 0
|
||||
for j in range(i):
|
||||
if (i+i-j-1) > (len(pattern)-1): continue
|
||||
for p in range(len(pattern[j])):
|
||||
if pattern[i+i-j-1][p] != pattern[j][p]:
|
||||
smudges += 1
|
||||
if smudges == 1: return i
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
lines = open(sys.argv[1]).read()
|
||||
patterns = lines[:-1].split('\n\n')
|
||||
patterns = [[list(n) for n in p.split('\n')] for p in patterns]
|
||||
|
||||
res1, res2 = 0, 0
|
||||
for pattern in patterns:
|
||||
res1 += 100 * find_reflexion(pattern)
|
||||
res2 += 100 * find_smudged_reflexion(pattern)
|
||||
vert = np.transpose(pattern)
|
||||
res1 += find_reflexion(vert)
|
||||
res2 += find_smudged_reflexion(vert)
|
||||
|
||||
# challenge 1
|
||||
res1 = str(res1)
|
||||
print(f"challenge 1:\n{res1}\n")
|
||||
|
||||
# challenge 2
|
||||
res2 = str(res2)
|
||||
print(f"challenge 2:\n{res2}\n")
|
||||
|
||||
Reference in new issue
Block a user