parent
5dc9ff995a
commit
cb0d71d1a2
5 changed files with 3068 additions and 0 deletions
@ -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) |
@ -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) |
Loading…
Reference in new issue