03
This commit is contained in:
28
03/03-1.py
Normal file
28
03/03-1.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
file = "./input.txt"
|
||||||
|
from time import time
|
||||||
|
start_time = time()
|
||||||
|
|
||||||
|
def check_line(l:str)->bool:
|
||||||
|
l=sorted(list(map(int,l.split())))
|
||||||
|
if l[0]+l[1] > l[2]:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sol = 0
|
||||||
|
input_file = open(file, "r")
|
||||||
|
for line in input_file:
|
||||||
|
line = line.strip()
|
||||||
|
if line == "":
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
if check_line(line):
|
||||||
|
sol += 1
|
||||||
|
input_file.close()
|
||||||
|
|
||||||
|
print(f"Solution - Part1: {sol}")
|
||||||
|
print(f'Runtime: {time()-start_time:.4f} s')
|
||||||
37
03/03-2.py
Normal file
37
03/03-2.py
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
file = "./input.txt"
|
||||||
|
from time import time
|
||||||
|
start_time = time()
|
||||||
|
|
||||||
|
def check_triple(triple:list[int])->bool:
|
||||||
|
triple=sorted(triple)
|
||||||
|
if triple[0]+triple[1] > triple[2]:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def read_input(filename:str)->list[list[int]]:
|
||||||
|
out = []
|
||||||
|
input_file = open(filename, "r")
|
||||||
|
for line in input_file:
|
||||||
|
line = line.strip()
|
||||||
|
if line == "":
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
out.append(list(map(int,line.split())))
|
||||||
|
input_file.close()
|
||||||
|
return out
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sol = 0
|
||||||
|
data = read_input(file)
|
||||||
|
for l in range(0,len(data),3):
|
||||||
|
for r in range(3):
|
||||||
|
if check_triple([data[l][r],data[l+1][r],data[l+2][r]]):
|
||||||
|
sol += 1
|
||||||
|
|
||||||
|
|
||||||
|
print(f"Solution - Part2: {sol}")
|
||||||
|
print(f'Runtime: {time()-start_time:.4f} s')
|
||||||
1734
03/input.txt
Normal file
1734
03/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user