Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ProcessFile(fileName) {
- FileRead, data, % fileName
- map := []
- For k, v in StrSplit(data, "`n") {
- if (v = "")
- continue
- map.push(StrSplit(v))
- }
- return map
- }
- CountVisibleToTop(cell, map, x, y) {
- visibleTrees := 0
- while (y > 1) {
- y--
- visibleTrees++
- if (cell <= map[y][x])
- break
- }
- return visibleTrees
- }
- CountVisibleToBottom(cell, map, x, y, maxY) {
- visibleTrees := 0
- while (y < maxY) {
- y++
- visibleTrees++
- if (cell <= map[y][x])
- break
- }
- return visibleTrees
- }
- CountVisibleToLeft(cell, map, x, y) {
- visibleTrees := 0
- while (x > 1) {
- x--
- visibleTrees++
- if (cell <= map[y][x])
- break
- }
- return visibleTrees
- }
- CountVisibleToRight(cell, map, x, y, maxX) {
- visibleTrees := 0
- while (x < maxX) {
- x++
- visibleTrees++
- if (cell <= map[y][x])
- break
- }
- return visibleTrees
- }
- CalculateScenicScore(cell, map, x, y, maxX, maxY) {
- return CountVisibleToTop( cell, map, x, y)
- * CountVisibleToBottom(cell, map, x, y, maxY)
- * CountVisibleToLeft( cell, map, x, y)
- * CountVisibleToRight( cell, map, x, y, maxX)
- }
- ProcessData(data) {
- maxScenicScore := 0
- maxY := data.count()
- maxX := data[1].count()
- y := 2
- while (y < maxY) {
- x := 2
- while (x < maxX) {
- cell := data[y][x]
- maxScenicScore := max(maxScenicScore, CalculateScenicScore(cell, data, x, y, maxX, maxY))
- x++
- }
- y++
- }
- return maxScenicScore
- }
- msgbox, % ProcessData(ProcessFile(A_ScriptDir "\aoc8.txt"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement