File size: 2,006 Bytes
0f06ae9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
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() |