anonymous1184

Advent of Code 2020.3 AHK

Dec 3rd, 2020 (edited)
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. staticMap := ["..##......."
  2.              , "#...#...#.."
  3.              , ".#....#..#."
  4.              , "..#.#...#.#"
  5.              , ".#...##..#."
  6.              , "..#.##....."
  7.              , ".#.#.#....#"
  8.              , ".#........#"
  9.              , "#.##...#..."
  10.              , "#...##....#"
  11.              , ".#..#...#.#"]
  12.  
  13. treeCount := countTrees(staticMap, trajectory)
  14. OutputDebug, % "Test: " (treeCount = 7 && trajectory = "OXOXXOXXXX" ? "PASS" : "FAIL") "`n"
  15.  
  16. randomMap := genMap()
  17. treeCount := countTrees(randomMap)
  18. OutputDebug, % "Trees found in trajectory: " treeCount "`n"
  19.  
  20. randomMap := genMap(20, 20)
  21. treeCount := countTrees(randomMap, trajectory)
  22. OutputDebug, % "Trees found in trajectory: " treeCount " | Trajectory: " trajectory "`n"
  23.  
  24. genMap(cols := 11, rows := 11)
  25. {
  26.     map := []
  27.     loop, % rows
  28.     {
  29.         row := ""
  30.         loop, % cols
  31.         {
  32.             Random, tree, 0, 1
  33.             row .= (tree ? "#" : ".")
  34.         }
  35.         map.Push(row)
  36.     }
  37.     return map
  38. }
  39.  
  40. countTrees(map, ByRef trajectory := "")
  41. {
  42.     treeCount := 0
  43.     , landPoint := 1
  44.     , trajectory := ""
  45.     , startRow := map.RemoveAt(1)
  46.     , rowLength := StrLen(startRow)
  47.     for i,row in map
  48.     {
  49.         landPoint += 3
  50.         if (landPoint > rowLength)
  51.         {
  52.             landPoint := (landPoint - rowLength)
  53.         }
  54.  
  55.         if (SubStr(row, landPoint, 1) = "#")
  56.         {
  57.             treeCount++
  58.             , trajectory .= "X"
  59.         }
  60.         else
  61.         {
  62.             trajectory .= "O"
  63.         }
  64.  
  65.     }
  66.     return treeCount
  67. }
  68.  
Add Comment
Please, Sign In to add comment