From a266fb68b5d73b36e1db22e0bfc05cdb5ea9a932 Mon Sep 17 00:00:00 2001 From: Jake Date: Thu, 2 Dec 2021 07:44:39 +0000 Subject: [PATCH] Completed day 2, task 2 --- Day-2/day2-2.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Day-2/day2-2.py diff --git a/Day-2/day2-2.py b/Day-2/day2-2.py new file mode 100644 index 0000000..f3688b1 --- /dev/null +++ b/Day-2/day2-2.py @@ -0,0 +1,26 @@ +#!/usr/bin/python3 + +# Variables to hold our position. +x = 0 +z = 0 +aim = 0 + +# Read in the input file. Split each line on the space. +with open('input.txt', 'r') as inputFile: + values = [] + for line in inputFile: + splitLine = line.split() + + # Check the first word of each line to decide what to do. + if splitLine[0] == "forward": + x = x + int(splitLine[1]) + z = z + (aim * int(splitLine[1])) + elif splitLine [0] == "down": + aim = aim + int(splitLine[1]) + elif splitLine [0] == "up": + aim = aim - int(splitLine[1]) + +# Print our final values. +print("X: " + str(x)) +print("Z: " + str(z)) +print("X * Z = " + str(x*z)) \ No newline at end of file