Skip to content

Commit

Permalink
Turned the Day3 Santa tracking into its own function and added code f…
Browse files Browse the repository at this point in the history
…or Day3 part 2.
  • Loading branch information
Zachary Boerner authored and Zachary Boerner committed Dec 20, 2015
1 parent 5fd57f7 commit 53f2d73
Showing 1 changed file with 30 additions and 15 deletions.
45 changes: 30 additions & 15 deletions Day3/Day3.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
def positionTracker(movementString, positionList):

curXPos = 0
curYPos = 0

for character in movementString:
if character is '<':
curXPos += 1
elif character is '>':
curXPos -= 1
elif character is '^':
curYPos += 1
elif character is 'v':
curYPos -= 1
positionList.append((curXPos, curYPos))


with open('Day3Input.txt', 'r') as file:
for line in file:
line = line.strip()

santaPos = [(0, 0)]
santaString = line[::2]
roboSantaString = line[1::2]

curXPos = 0
curYPos = 0
santaPosPart1 = [(0, 0)]
santaPosPart2 = [(0, 0)]
roboSantaPosPart2 = [(0, 0)]

for character in line:
if character is '<':
curXPos += 1
elif character is '>':
curXPos -= 1
elif character is '^':
curYPos += 1
elif character is 'v':
curYPos -= 1
santaPos.append((curXPos, curYPos))
positionTracker(line, santaPosPart1)
positionTracker(santaString, santaPosPart2)
positionTracker(roboSantaString, roboSantaPosPart2)

# Grid I used for figuring out the next calculation
# There will always be a dimension of 1 - Santa starts on the first square
Expand All @@ -31,8 +43,11 @@
# x x 8
# x x 9

uniqueHouses = list(set(santaPos))
print("Unique houses visited: %s" % len(uniqueHouses))
uniqueHouses = list(set(santaPosPart1))
print("Unique houses visited in Part 1: %s" % len(uniqueHouses))

uniqueHouses = list(set(santaPosPart2 + roboSantaPosPart2))
print("Unique houses visited in Part 2: %s" % len(uniqueHouses))



Expand Down

0 comments on commit 53f2d73

Please sign in to comment.