Skip to content

Instantly share code, notes, and snippets.

@G33kDude
Created December 19, 2020 17:20
Show Gist options
  • Save G33kDude/d5b0ccceed431641a7950539e8942bda to your computer and use it in GitHub Desktop.
Save G33kDude/d5b0ccceed431641a7950539e8942bda to your computer and use it in GitHub Desktop.
#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