From 2f3dd824d091e139898ee1b8a21769284fcdc2b2 Mon Sep 17 00:00:00 2001 From: tebarius Date: Sun, 10 Dec 2023 23:29:22 +0100 Subject: [PATCH] 10-1 dirty Solution --- .idea/inspectionProfiles/Project_Default.xml | 6 ++ 10/10-1-ex12.py | 89 ++++++++++++++++++++ 10/10-1-ex22.py | 89 ++++++++++++++++++++ 10/10-1.py | 50 ----------- 10/10-1a.py | 89 ++++++++++++++++++++ 10/10-2.py | 89 ++++++++++++++++++++ 6 files changed, 362 insertions(+), 50 deletions(-) create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 10/10-1-ex12.py create mode 100644 10/10-1-ex22.py delete mode 100644 10/10-1.py create mode 100644 10/10-1a.py create mode 100644 10/10-2.py diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..01ba32f --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/10/10-1-ex12.py b/10/10-1-ex12.py new file mode 100644 index 0000000..ec2f752 --- /dev/null +++ b/10/10-1-ex12.py @@ -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) + diff --git a/10/10-1-ex22.py b/10/10-1-ex22.py new file mode 100644 index 0000000..6db595d --- /dev/null +++ b/10/10-1-ex22.py @@ -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) + diff --git a/10/10-1.py b/10/10-1.py deleted file mode 100644 index b865170..0000000 --- a/10/10-1.py +++ /dev/null @@ -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,[])) diff --git a/10/10-1a.py b/10/10-1a.py new file mode 100644 index 0000000..2eb7924 --- /dev/null +++ b/10/10-1a.py @@ -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) + diff --git a/10/10-2.py b/10/10-2.py new file mode 100644 index 0000000..2eb7924 --- /dev/null +++ b/10/10-2.py @@ -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) +