days 1 and 2

main
Benjamin Kraft 3 years ago
parent 5dc9ff995a
commit cb0d71d1a2
  1. 8
      .idea/.gitignore
  2. 25
      01/01.py
  3. 2000
      01/input
  4. 35
      02/02.py
  5. 1000
      02/input

8
.idea/.gitignore vendored

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

@ -0,0 +1,25 @@
import math
values = []
with open("input", "r") as file:
for line in file.readlines():
values.append(int(line))
increases = 0
before = math.inf
for v in values:
if v > before:
increases += 1
before = v
print(increases)
increases = 0
before = math.inf
for i in range(len(values) - 2):
s = sum(values[i:i+3])
if s > before:
increases += 1
before = s
print(increases)

2000
01/input

File diff suppressed because it is too large Load Diff

@ -0,0 +1,35 @@
actions = []
with open("input", "r") as file:
for raw in file.read().splitlines():
cmd, amount = raw.split(" ")
actions.append((cmd, int(amount)))
x, depth = 0, 0
for cmd, amount in actions:
if cmd == "forward":
x += amount
if cmd == "up":
depth -= amount
if cmd == "down":
depth += amount
print(f"Horizontal: {x}")
print(f"Depth: {depth}")
print(x * depth)
x, depth, aim = 0, 0, 0
for cmd, amount in actions:
if cmd == "forward":
x += amount
depth += aim * amount
if cmd == "up":
aim -= amount
if cmd == "down":
aim += amount
print(f"Horizontal: {x}")
print(f"Depth: {depth}")
print(x * depth)

1000
02/input

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save