Skip to content

Commit

Permalink
14-2
Browse files Browse the repository at this point in the history
  • Loading branch information
koosvary committed Dec 15, 2024
1 parent 9e80daf commit 70f72b0
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.venv/
.vscode/
2023
2023
*screenshots/
70 changes: 70 additions & 0 deletions 2024/14/14-2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import re
import cv2
import numpy as np

testing = False # change this when doing the actual input

xPosition = []
yPosition = []
xVelocity = []
yVelocity = []

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

# numpy arrays can be made into pngs with openCV
tiles = np.zeros((height, width), dtype=np.int64)

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

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

xPosition.append(pX)
yPosition.append(pY)
xVelocity.append(vX)
yVelocity.append(vY)
tiles[pY, pX] = 1


numRobots = len(xPosition)
# Run this thing 10000 times and save them to PNGs.
# I'm not crazy, you're crazy
for i in range(10000):
for robot in range(numRobots):
pX = xPosition[robot]
pY = yPosition[robot]
vX = xVelocity[robot]
vY = yVelocity[robot]

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

xPosition[robot] = newPosX
yPosition[robot] = newPosY

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

tilesForImage = np.copy(tiles)

# Gotta make all the squares with bots be 255 otherwise OpenCV will make a heatmap
# Without this you'll see hotspots but never see the tree
tilesForImage[tilesForImage > 0] = 255

cv2.imwrite(f"2024/14/screenshots/img_{str(i+1).zfill(4)}.png", tilesForImage) # imwrite(filename, img[, params])
Binary file added 2024/14/img_7371.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 70f72b0

Please sign in to comment.