13-grrr
This commit is contained in:
70
13/13-1.py
Normal file
70
13/13-1.py
Normal file
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
data = []
|
||||
|
||||
# parse input
|
||||
input_file = open("input-ex", "r")
|
||||
pattern = []
|
||||
for line in input_file:
|
||||
line = line.strip()
|
||||
if line == "":
|
||||
data.append(pattern)
|
||||
pattern = []
|
||||
else:
|
||||
pattern.append(line)
|
||||
data.append(pattern)
|
||||
input_file.close()
|
||||
'''
|
||||
for i in range(len(data)):
|
||||
for _ in data[i]:
|
||||
print(_)
|
||||
print("================")
|
||||
'''
|
||||
|
||||
def find_vertikal_mirror(matrix):
|
||||
for s in range(1, len(matrix[0])):
|
||||
is_mirror = True
|
||||
for z in matrix:
|
||||
if s <= len(z) / 2:
|
||||
p1 = z[:s]
|
||||
p2 = z[s:]
|
||||
p2 = p2[::-1]
|
||||
p2 = p2[:s]
|
||||
print("1: ",s,p1,"-",p2)
|
||||
else:
|
||||
p2 = z[s:]
|
||||
p1 = z[:s]
|
||||
p1 = p1[::-1]
|
||||
p1 = p1[:len(p2)]
|
||||
print("2: ",s,p1,p2)
|
||||
if p1 != p2:
|
||||
is_mirror = False
|
||||
if is_mirror:
|
||||
return s
|
||||
return 0
|
||||
|
||||
|
||||
def find_horizontal_mirror(matrix):
|
||||
new_matrix = []
|
||||
for j in range(len(matrix[0])):
|
||||
new_matrix.append("".join([matrix[k][j] for k in range(len(matrix))]))
|
||||
for n in new_matrix:
|
||||
print(n)
|
||||
print("_____________________")
|
||||
return find_vertikal_mirror(new_matrix)
|
||||
|
||||
|
||||
solution = 0
|
||||
for m in data:
|
||||
print(m)
|
||||
for mn in m:
|
||||
print(mn)
|
||||
vert = find_vertikal_mirror(m)
|
||||
horz = find_horizontal_mirror(m)
|
||||
print(vert, horz)
|
||||
if vert == 0:
|
||||
solution += 100 * find_horizontal_mirror(m)
|
||||
else:
|
||||
solution += vert
|
||||
|
||||
print("Lösung:", solution)
|
||||
48
13/input-ex
Normal file
48
13/input-ex
Normal file
@@ -0,0 +1,48 @@
|
||||
#.##..##.
|
||||
..#.##.#.
|
||||
##......#
|
||||
##......#
|
||||
..#.##.#.
|
||||
..##..##.
|
||||
#.#.##.#.
|
||||
|
||||
#...##..#
|
||||
#....#..#
|
||||
..##..###
|
||||
#####.##.
|
||||
#####.##.
|
||||
..##..###
|
||||
#....#..#
|
||||
|
||||
#..######.#....
|
||||
####....#..##.#
|
||||
####....#..##.#
|
||||
#..######.#....
|
||||
.#...#####..#..
|
||||
#...####...#.#.
|
||||
##...#.#...#..#
|
||||
.##.##.#.....#.
|
||||
..#..##....##..
|
||||
..#.....#..##.#
|
||||
##...#...#####.
|
||||
##...#...#####.
|
||||
..#..#..#..##.#
|
||||
|
||||
####.##...##.
|
||||
.##.#.##..##.
|
||||
.##....###..#
|
||||
####.........
|
||||
#..#.#.#.....
|
||||
#..######.###
|
||||
#..###..#....
|
||||
#..#####.....
|
||||
#####....#..#
|
||||
....#.....##.
|
||||
#..#......##.
|
||||
.##..##.#####
|
||||
.##.#...#####
|
||||
.....#.#..##.
|
||||
.##...#..#..#
|
||||
|
||||
AA--AA--AA
|
||||
AB-CDDC-BA
|
||||
Reference in New Issue
Block a user