Skip to content

Commit

Permalink
14-1
Browse files Browse the repository at this point in the history
  • Loading branch information
koosvary committed Dec 14, 2024
1 parent 4ec8072 commit 9e80daf
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 0 deletions.
67 changes: 67 additions & 0 deletions 2024/14/14-1-brute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import re

testing = False # change this when doing the actual input
seconds = 100

tiles = []

def quadrantSafetyScore(startRow, endRow, startCol, endCol):
sum = 0
for i in range(startRow, endRow):
for j in range(startCol, endCol):
sum += tiles[i][j]
return sum

def move(position, velocity, secondsToGo):
if secondsToGo == 0:
return

pX, pY = position
vX, vY = velocity

newPosX = (pX + vX) % width
newPosY = (pY + vY) % height

tiles[pY][pX] -= 1
tiles[newPosY][newPosX] += 1

move((newPosX,newPosY), velocity, secondsToGo - 1)

match testing:
case True:
inputPath = "2024/14/testinput.txt"
width = 11
height = 7
case False:
inputPath = "2024/14/input.txt"
width = 101
height = 103

for i in range(height):
tiles.append([])
for j in range(width):
tiles[i].append(0);


with open(inputPath) as f:
for line in f:
line = line.strip()

regex = re.findall(r"(-*\d+)", line)

startPosition = (int(regex[0]), int(regex[1]))
velocity = (int(regex[2]), int(regex[3]))

pX, pY = startPosition
tiles[pY][pX] += 1
move(startPosition, velocity, seconds)

middleRow = int(height / 2)
middleCol = int(width / 2)

q1 = quadrantSafetyScore(0, middleRow, 0, middleCol)
q2 = quadrantSafetyScore(0, middleRow, middleCol + 1, width)
q3 = quadrantSafetyScore(middleRow + 1, height, 0, middleCol)
q4 = quadrantSafetyScore(middleRow + 1, height, middleCol + 1, width)

print(q1 * q2 * q3 * q4)
50 changes: 50 additions & 0 deletions 2024/14/14-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import re

testing = False # change this when doing the actual input
seconds = 100

tiles = []

def quadrantSafetyScore(startRow, endRow, startCol, endCol):
sum = 0
for i in range(startRow, endRow):
for j in range(startCol, endCol):
sum += tiles[i][j]
return sum

match testing:
case True:
inputPath = "2024/14/testinput.txt"
width = 11
height = 7
case False:
inputPath = "2024/14/input.txt"
width = 101
height = 103

for i in range(height):
tiles.append([])
for j in range(width):
tiles[i].append(0);


with open(inputPath) as f:
for line in f:
line = line.strip()

pX, pY, vX, vY = map(int, re.findall(r"(-*\d+)", line))

newPosX = (pX + vX * seconds) % width
newPosY = (pY + vY * seconds) % height

tiles[newPosY][newPosX] += 1

middleRow = int(height / 2)
middleCol = int(width / 2)

q1 = quadrantSafetyScore(0, middleRow, 0, middleCol)
q2 = quadrantSafetyScore(0, middleRow, middleCol + 1, width)
q3 = quadrantSafetyScore(middleRow + 1, height, 0, middleCol)
q4 = quadrantSafetyScore(middleRow + 1, height, middleCol + 1, width)

print(q1 * q2 * q3 * q4)
12 changes: 12 additions & 0 deletions 2024/14/testinput.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
p=0,4 v=3,-3
p=6,3 v=-1,-3
p=10,3 v=-1,2
p=2,0 v=2,-1
p=0,0 v=1,3
p=3,0 v=-2,-2
p=7,6 v=-1,-3
p=3,0 v=-1,-2
p=9,3 v=2,3
p=7,3 v=-1,2
p=2,4 v=2,-3
p=9,5 v=-3,-3

0 comments on commit 9e80daf

Please sign in to comment.