aoc / year_2021 /code /day_2.py
YassineAlouini
Start
0f06ae9
raw
history blame
2.01 kB
with open("/home/yassinealouini/Documents/code/advent_of_code/aoc/year_2021/data/2.txt") as f:
data = f.read().rstrip().split("\n")
directions = []
steps = []
for row in data:
direction, step = row.rstrip().split(" ")
directions.append(direction)
steps.append(int(step))
def main():
start = [0, 0]
for direction, step in zip(directions, steps):
if direction == "forward":
start[0] += step
if direction == "down":
start[1] += step
if direction == "up":
start[1] -= step
print("Solution to part I is: ", start[0] * start[1])
start = [0, 0, 0]
for direction, step in zip(directions, steps):
if direction == "forward":
start[0] += step
start[1] += step * start[2]
if direction == "down":
start[2] += step
if direction == "up":
start[2] -= step
print("Solution to part II is: ", start[0] * start[1])
def streamlit_2(day_input):
import streamlit as st
data = day_input.rstrip().split("\n")
print(data)
directions = []
steps = []
for row in data:
direction, step = row.rstrip().split(" ")
directions.append(direction)
steps.append(int(step))
start = [0, 0]
for direction, step in zip(directions, steps):
if direction == "forward":
start[0] += step
if direction == "down":
start[1] += step
if direction == "up":
start[1] -= step
st.write("Solution to part I is: ", start[0] * start[1])
start = [0, 0, 0]
for direction, step in zip(directions, steps):
if direction == "forward":
start[0] += step
start[1] += step * start[2]
if direction == "down":
start[2] += step
if direction == "up":
start[2] -= step
st.write("Solution to part II is: ", start[0] * start[1])
if __name__ == "__main__":
main()