4-2 fertig

This commit is contained in:
2024-01-01 22:41:12 +01:00
parent 0ea6ce43e5
commit d048984091
4 changed files with 1071 additions and 0 deletions

30
04/04-1.py Normal file
View File

@@ -0,0 +1,30 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
data = []
# parse input
input_file = open("input", "r")
for line in input_file:
line = line.strip()
line = line.replace(",", "-").split("-")
tt = []
for t in line:
tt.append(int(t))
data.append(tt)
input_file.close()
def a_is_b(a1, a2, b1, b2):
if a1 >= b1 and a2 <= b2:
print(a1, a2, b1, b2)
return True
return False
counter = 0
for d in data:
if a_is_b(d[0], d[1], d[2], d[3]) or a_is_b(d[2], d[3], d[0], d[1]):
# print(d)
counter += 1
print("Lösung:", counter)

35
04/04-2.py Normal file
View File

@@ -0,0 +1,35 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
data = []
# parse input
input_file = open("input", "r")
for line in input_file:
line = line.strip()
line = line.replace(",", "-").split("-")
tt = []
for t in line:
tt.append(int(t))
data.append(tt)
input_file.close()
c = 0
def a_overlaps_b(a1, a2, b1, b2):
if a2 >= b1 and a1 <= b2:
global c
c += 1
print(a1, a2, b1, b2)
return True
return False
counter = 0
for d in data:
if a_overlaps_b(d[0], d[1], d[2], d[3]) or a_overlaps_b(d[2], d[3], d[0], d[1]):
# print(d)
counter += 1
print("Lösung:", counter)
print(c)

1000
04/input Normal file

File diff suppressed because it is too large Load Diff

6
04/input-ex Normal file
View File

@@ -0,0 +1,6 @@
2-4,6-8
2-3,4-5
5-7,7-9
2-8,3-7
6-6,4-6
2-6,4-8