Add day 1-5
This commit is contained in:
Executable
+33
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
filename = "example.txt"
|
||||
filename = "input.txt"
|
||||
|
||||
with open(filename) as f:
|
||||
data = f.readlines()
|
||||
|
||||
|
||||
l = []
|
||||
r = []
|
||||
|
||||
for line in data:
|
||||
split = line.split(" ")
|
||||
l.append(int(split[0]))
|
||||
r.append(int(split[-1].strip()))
|
||||
|
||||
if len(l) != len(r):
|
||||
raise Exception("lists must be the same length")
|
||||
|
||||
l_sort = sorted(l)
|
||||
r_sort = sorted(r)
|
||||
|
||||
distance = 0
|
||||
for i in range(len(l)):
|
||||
print(f"l: {l_sort[i]}, r: {r_sort[i]}")
|
||||
v = l_sort[i] - r_sort[i]
|
||||
d = abs(v)
|
||||
print(f"v: {v}, d: {d}")
|
||||
distance = distance + d
|
||||
print("")
|
||||
|
||||
print(distance)
|
||||
@@ -0,0 +1,6 @@
|
||||
3 4
|
||||
4 3
|
||||
2 5
|
||||
1 3
|
||||
3 9
|
||||
3 3
|
||||
@@ -0,0 +1,14 @@
|
||||
[tool.poetry]
|
||||
name = "aoc"
|
||||
version = "0.1.0"
|
||||
description = ""
|
||||
authors = ["restitux <restitux@ohea.xyz>"]
|
||||
readme = "README.md"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.12"
|
||||
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
filename = "example.txt"
|
||||
filename = "input.txt"
|
||||
|
||||
with open(filename) as f:
|
||||
data = f.readlines()
|
||||
|
||||
|
||||
l = []
|
||||
r = []
|
||||
|
||||
for line in data:
|
||||
split = line.split(" ")
|
||||
l.append(int(split[0]))
|
||||
r.append(int(split[-1].strip()))
|
||||
|
||||
if len(l) != len(r):
|
||||
raise Exception("lists must be the same length")
|
||||
|
||||
total = 0
|
||||
|
||||
for e in l:
|
||||
count = r.count(e)
|
||||
result = e * count
|
||||
print(f"count: {count}, result: {result}")
|
||||
total += result
|
||||
print("")
|
||||
|
||||
print(total)
|
||||
@@ -0,0 +1,6 @@
|
||||
3 4
|
||||
4 3
|
||||
2 5
|
||||
1 3
|
||||
3 9
|
||||
3 3
|
||||
@@ -0,0 +1,14 @@
|
||||
[tool.poetry]
|
||||
name = "aoc"
|
||||
version = "0.1.0"
|
||||
description = ""
|
||||
authors = ["restitux <restitux@ohea.xyz>"]
|
||||
readme = "README.md"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.12"
|
||||
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
Reference in New Issue
Block a user