Add day 1-5
This commit is contained in:
Executable
+49
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
filename = "example.txt"
|
||||
filename = "input.txt"
|
||||
|
||||
def valid_deltas(report):
|
||||
for x in range(len(report) - 1):
|
||||
if not (1 <= abs(report[x] - report[x + 1]) <= 3):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def is_ascending(report):
|
||||
x = [
|
||||
report[i] < report[i + 1]
|
||||
for i in range((len(report) - 1))
|
||||
]
|
||||
print(x)
|
||||
return all(x)
|
||||
|
||||
def is_decending(report):
|
||||
return is_ascending(list(reversed(report)))
|
||||
|
||||
reports = []
|
||||
|
||||
with open(filename) as f:
|
||||
for line in f.readlines():
|
||||
reports.append([int(x) for x in line.strip().split(" ")])
|
||||
|
||||
valid_reports = 0
|
||||
|
||||
for report in reports:
|
||||
print(", ".join([str(x) for x in report]))
|
||||
ascending = is_ascending(report)
|
||||
decending = is_decending(report)
|
||||
deltas = valid_deltas(report)
|
||||
print(f"ascending: {ascending}")
|
||||
print(f"decending: {decending}")
|
||||
print(f"deltas: {deltas}")
|
||||
valid = (ascending or decending) and deltas
|
||||
print(f"valid: {valid}")
|
||||
print()
|
||||
print()
|
||||
if valid:
|
||||
valid_reports += 1
|
||||
|
||||
print(f"valid_reports: {valid_reports}")
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
7 6 4 2 1
|
||||
1 2 7 8 9
|
||||
9 7 6 2 1
|
||||
1 3 2 4 5
|
||||
8 6 4 4 1
|
||||
1 3 6 7 9
|
||||
@@ -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