Add code for 2015 advent that I did historically.
This commit is contained in:
parent
13968ed94e
commit
9e9e556c73
25 changed files with 598 additions and 0 deletions
10
day_1/info.md
Normal file
10
day_1/info.md
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
Problem: https://adventofcode.com/2015/day/1
|
||||
|
||||
|
||||
Part 1:
|
||||
Calculating the delta
|
||||
|
||||
|
||||
Part 2:
|
||||
Calculating the first step in the instructions to cause Santa to go into the
|
||||
basement
|
||||
13
day_1/part_1.py
Normal file
13
day_1/part_1.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
data = input("Input Instruction set: \n")
|
||||
|
||||
|
||||
# floor_delta = 0
|
||||
|
||||
# for char in data:
|
||||
# if char == "(": floor_delta += 1
|
||||
# elif char == ")": floor_delta -= 1
|
||||
|
||||
|
||||
# This is equivalent to commented out code above
|
||||
# DONE FOR FUN, Wouldn't use in production...
|
||||
print(sum([ 1 if char == "(" else -1 for char in data]))
|
||||
23
day_1/part_2.py
Normal file
23
day_1/part_2.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
data = input("Input Instruction set: \n")
|
||||
|
||||
floor_delta = 0
|
||||
first_negative_instruction = None
|
||||
|
||||
|
||||
# Run through instruction set
|
||||
for index in range(len(data)):
|
||||
char = data[index]
|
||||
|
||||
# Increment floor delta
|
||||
if char == "(":
|
||||
floor_delta += 1
|
||||
|
||||
# Decrement floor delta and track what the first index that causes us to go
|
||||
# negative is.
|
||||
elif char == ")":
|
||||
floor_delta -= 1
|
||||
if floor_delta == -1 and not first_negative_instruction:
|
||||
first_negative_instruction = index + 1
|
||||
break
|
||||
|
||||
print(f"First Negative Instruction: {first_negative_instruction}")
|
||||
Loading…
Add table
Add a link
Reference in a new issue