10-1 dirty Solution

This commit is contained in:
2023-12-10 23:29:22 +01:00
parent 9583fa64ae
commit 2f3dd824d0
6 changed files with 362 additions and 50 deletions

View File

@@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyUnboundLocalVariableInspection" enabled="false" level="WARNING" enabled_by_default="false" />
</profile>
</component>

89
10/10-1-ex12.py Normal file
View File

@@ -0,0 +1,89 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
part_sum = 0
matrix = []
# read matrix like day 3
input_file = open("input-ex11", "r")
for line in input_file:
matrix.append(line.strip())
input_file.close()
zeilen = len(matrix)
spalten = len(matrix[0])
# Ausgabe Matrix und Startposition finden
for i in range(len(matrix)):
if "S" in matrix[i]:
zs = i
print(matrix[i])
for j in range(len(matrix[zs])):
if "S" in matrix[zs][j]:
ss = j
start = [zs, ss]
print()
print(f"Startposition: {start}")
def come_from(z, s, pre):
if pre[0]+1 == z:
return "N"
elif pre[0]-1 == z:
return "S"
elif pre[1]+1 == s:
return "W"
elif pre[1]-1 == s:
return "E"
else:
return "A"
def where_to_go(z, s, pre):
pipe = matrix[z][s]
come = come_from(z, s, pre)
if pipe == "S":
return "Ende"
if come == "N" and pipe == "|":
return z+1, s
elif come == "S" and pipe == "|":
return z-1, s
elif come == "E" and pipe == "-":
return z, s-1
elif come == "W" and pipe == "-":
return z, s+1
elif come == "N" and pipe == "L":
return z, s+1
elif come == "E" and pipe == "L":
return z-1, s
elif come == "W" and pipe == "7":
return z+1, s
elif come == "S" and pipe == "7":
return z, s-1
elif come == "N" and pipe == "J":
return z, s-1
elif come == "W" and pipe == "J":
return z-1, s
elif come == "E" and pipe == "F":
return z+1, s
elif come == "S" and pipe == "F":
return z, s+1
previous = (start[0], start[1])
aktuell = [2, 1]
count = 1
while True:
new = where_to_go(aktuell[0], aktuell[1], previous)
print(aktuell, previous, new)
if new == "Ende":
break
else:
count += 1
previous = (aktuell[0], aktuell[1])
aktuell = [new[0], new[1]]
print("Counter:", count)
print("HalfCounter:", count/2)

89
10/10-1-ex22.py Normal file
View File

@@ -0,0 +1,89 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
part_sum = 0
matrix = []
# read matrix like day 3
input_file = open("input-ex22", "r")
for line in input_file:
matrix.append(line.strip())
input_file.close()
zeilen = len(matrix)
spalten = len(matrix[0])
# Ausgabe Matrix und Startposition finden
for i in range(len(matrix)):
if "S" in matrix[i]:
zs = i
print(matrix[i])
for j in range(len(matrix[zs])):
if "S" in matrix[zs][j]:
ss = j
start = [zs, ss]
print()
print(f"Startposition: {start}")
def come_from(z, s, pre):
if pre[0]+1 == z:
return "N"
elif pre[0]-1 == z:
return "S"
elif pre[1]+1 == s:
return "W"
elif pre[1]-1 == s:
return "E"
else:
return "A"
def where_to_go(z, s, pre):
pipe = matrix[z][s]
come = come_from(z, s, pre)
if pipe == "S":
return "Ende"
if come == "N" and pipe == "|":
return z+1, s
elif come == "S" and pipe == "|":
return z-1, s
elif come == "E" and pipe == "-":
return z, s-1
elif come == "W" and pipe == "-":
return z, s+1
elif come == "N" and pipe == "L":
return z, s+1
elif come == "E" and pipe == "L":
return z-1, s
elif come == "W" and pipe == "7":
return z+1, s
elif come == "S" and pipe == "7":
return z, s-1
elif come == "N" and pipe == "J":
return z, s-1
elif come == "W" and pipe == "J":
return z-1, s
elif come == "E" and pipe == "F":
return z+1, s
elif come == "S" and pipe == "F":
return z, s+1
previous = (start[0], start[1])
aktuell = [start[0]+1, start[1]]
count = 1
while True:
new = where_to_go(aktuell[0], aktuell[1], previous)
print(aktuell, previous, new)
if new == "Ende":
break
else:
count += 1
previous = (aktuell[0], aktuell[1])
aktuell = [new[0], new[1]]
print("Counter:", count)
print("HalfCounter:", count/2)

View File

@@ -1,50 +0,0 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
part_sum = 0
matrix = []
# read matrix like day 3
input_file = open("input", "r")
for line in input_file:
matrix.append(line.strip())
input_file.close()
zeilen = len(matrix)
spalten = len(matrix[0])
# Ausgabe Matrix und Startposition finden
for i in range(len(matrix)):
if "S" in matrix[i]:
zs = i
print(matrix[i])
for j in range(len(matrix[zs])):
if "S" in matrix[zs][j]:
ss = j
print()
print(f"Startposition: {zs}, {ss}")
def where_to_go(z, s, prev):
try:
if [z, s] != prev and (matrix[z-1][s] == "F" or matrix[z-1][s] == "7" or matrix[z-1][s] == "|"):
return z-1, s
except IndexError:
pass
try:
if [z, s] != prev and (matrix[z+1][s] == "L" or matrix[z+1][s] == "J" or matrix[z-1][s] == "|"):
return z+1, s
except IndexError:
pass
try:
if [z, s] != prev and (matrix[z][s+1] == "J" or matrix[z][s+1] == "7"):
return z, s+1
except IndexError:
pass
try:
if [z, s] != prev and (matrix[z][s-1] == "F" or matrix[z][s-1] == "L"):
return z, s-1
except IndexError:
pass
print(where_to_go(1,1,[]))

89
10/10-1a.py Normal file
View File

@@ -0,0 +1,89 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
part_sum = 0
matrix = []
# read matrix like day 3
input_file = open("input", "r")
for line in input_file:
matrix.append(line.strip())
input_file.close()
zeilen = len(matrix)
spalten = len(matrix[0])
# Ausgabe Matrix und Startposition finden
for i in range(len(matrix)):
if "S" in matrix[i]:
zs = i
print(matrix[i])
for j in range(len(matrix[zs])):
if "S" in matrix[zs][j]:
ss = j
start = [zs, ss]
print()
print(f"Startposition: {start}")
def come_from(z, s, pre):
if pre[0]+1 == z:
return "N"
elif pre[0]-1 == z:
return "S"
elif pre[1]+1 == s:
return "W"
elif pre[1]-1 == s:
return "E"
else:
return "A"
def where_to_go(z, s, pre):
pipe = matrix[z][s]
come = come_from(z, s, pre)
if pipe == "S":
return "Ende"
if come == "N" and pipe == "|":
return z+1, s
elif come == "S" and pipe == "|":
return z-1, s
elif come == "E" and pipe == "-":
return z, s-1
elif come == "W" and pipe == "-":
return z, s+1
elif come == "N" and pipe == "L":
return z, s+1
elif come == "E" and pipe == "L":
return z-1, s
elif come == "W" and pipe == "7":
return z+1, s
elif come == "S" and pipe == "7":
return z, s-1
elif come == "N" and pipe == "J":
return z, s-1
elif come == "W" and pipe == "J":
return z-1, s
elif come == "E" and pipe == "F":
return z+1, s
elif come == "S" and pipe == "F":
return z, s+1
previous = (start[0], start[1])
aktuell = [start[0]-1, start[1]]
count = 1
while True:
new = where_to_go(aktuell[0], aktuell[1], previous)
print(aktuell, previous, new)
if new == "Ende":
break
else:
count += 1
previous = (aktuell[0], aktuell[1])
aktuell = [new[0], new[1]]
print("Counter:", count)
print("HalfCounter:", count/2)

89
10/10-2.py Normal file
View File

@@ -0,0 +1,89 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
part_sum = 0
matrix = []
# read matrix like day 3
input_file = open("input", "r")
for line in input_file:
matrix.append(line.strip())
input_file.close()
zeilen = len(matrix)
spalten = len(matrix[0])
# Ausgabe Matrix und Startposition finden
for i in range(len(matrix)):
if "S" in matrix[i]:
zs = i
print(matrix[i])
for j in range(len(matrix[zs])):
if "S" in matrix[zs][j]:
ss = j
start = [zs, ss]
print()
print(f"Startposition: {start}")
def come_from(z, s, pre):
if pre[0]+1 == z:
return "N"
elif pre[0]-1 == z:
return "S"
elif pre[1]+1 == s:
return "W"
elif pre[1]-1 == s:
return "E"
else:
return "A"
def where_to_go(z, s, pre):
pipe = matrix[z][s]
come = come_from(z, s, pre)
if pipe == "S":
return "Ende"
if come == "N" and pipe == "|":
return z+1, s
elif come == "S" and pipe == "|":
return z-1, s
elif come == "E" and pipe == "-":
return z, s-1
elif come == "W" and pipe == "-":
return z, s+1
elif come == "N" and pipe == "L":
return z, s+1
elif come == "E" and pipe == "L":
return z-1, s
elif come == "W" and pipe == "7":
return z+1, s
elif come == "S" and pipe == "7":
return z, s-1
elif come == "N" and pipe == "J":
return z, s-1
elif come == "W" and pipe == "J":
return z-1, s
elif come == "E" and pipe == "F":
return z+1, s
elif come == "S" and pipe == "F":
return z, s+1
previous = (start[0], start[1])
aktuell = [start[0]-1, start[1]]
count = 1
while True:
new = where_to_go(aktuell[0], aktuell[1], previous)
print(aktuell, previous, new)
if new == "Ende":
break
else:
count += 1
previous = (aktuell[0], aktuell[1])
aktuell = [new[0], new[1]]
print("Counter:", count)
print("HalfCounter:", count/2)