Days 5 and 6.1 done
This commit is contained in:
25
5/a.py
Normal file
25
5/a.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
with open("input", "r") as f:
|
||||||
|
lines = f.read().splitlines()
|
||||||
|
|
||||||
|
ranges = []
|
||||||
|
ingredients = []
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
if not line:
|
||||||
|
continue
|
||||||
|
if "-" in line:
|
||||||
|
start, end = line.split("-")
|
||||||
|
ranges.append((int(start), int(end)))
|
||||||
|
else:
|
||||||
|
ingredients.append(int(line))
|
||||||
|
|
||||||
|
s = 0
|
||||||
|
|
||||||
|
for ingredient in ingredients:
|
||||||
|
for range_ in ranges:
|
||||||
|
start, end = range_
|
||||||
|
if start <= ingredient <= end:
|
||||||
|
s += 1
|
||||||
|
break
|
||||||
|
|
||||||
|
print(s)
|
||||||
9
5/b.py
Normal file
9
5/b.py
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
with open("input", "r") as f:
|
||||||
|
lines = f.read().splitlines()
|
||||||
|
|
||||||
|
ranges = []
|
||||||
|
|
||||||
|
for line in lines:
|
||||||
|
if "-" in line:
|
||||||
|
start, end = line.split("-")
|
||||||
|
ranges.append((int(start), int(end)))
|
||||||
21
6/a.py
Normal file
21
6/a.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
from functools import reduce
|
||||||
|
from operator import mul
|
||||||
|
|
||||||
|
|
||||||
|
with open("input", "r") as f:
|
||||||
|
lines = f.read().splitlines()
|
||||||
|
|
||||||
|
lines = [line.split() for line in lines]
|
||||||
|
|
||||||
|
transposed = [[lines[j][i] for j in range(len(lines))] for i in range(len(lines[0]))]
|
||||||
|
|
||||||
|
s = 0
|
||||||
|
|
||||||
|
for line in transposed:
|
||||||
|
operands, operator = list(map(int, line[:-1])), line[-1]
|
||||||
|
if operator == "+":
|
||||||
|
s += sum(operands)
|
||||||
|
else:
|
||||||
|
s += reduce(mul, operands, 1)
|
||||||
|
|
||||||
|
print(s)
|
||||||
Reference in New Issue
Block a user