Skip to content

Instantly share code, notes, and snippets.

@G33kDude

G33kDude/day3.ahk

Created Dec 19, 2020
Embed
What would you like to do?
#NoEnv
SetBatchLines, -1
map := FileOpen(A_Desktop "\day3.txt", "r").Read()
map := StrSplit(map, "`n", "`r")
; --- Part 1 ---
for y, row in map
{
trees += SubStr(row, x+1, 1) == "#"
x := Mod(x+3, StrLen(row))
}
MsgBox, % Format("Slope (3, 1) had tree count: {}", trees)
; --- Part 2 ---
sumproduct := 1
for i, slope in [[1, 1], [3, 1], [5, 1], [7, 1], [1, 2]]
{
x := 0, y := 0, trees := 0
while (y += slope[2], x := Mod(x+slope[1], StrLen(map[1]))) < map.Length()
trees += SubStr(map[y+1], x+1, 1) == "#"
sumproduct *= trees
}
MsgBox, % Format("Slopes had tree product: {}", Clipboard := sumproduct)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment