Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- staticMap := ["..##......."
- , "#...#...#.."
- , ".#....#..#."
- , "..#.#...#.#"
- , ".#...##..#."
- , "..#.##....."
- , ".#.#.#....#"
- , ".#........#"
- , "#.##...#..."
- , "#...##....#"
- , ".#..#...#.#"]
- treeCount := countTrees(staticMap, trajectory)
- OutputDebug, % "Test: " (treeCount = 7 && trajectory = "OXOXXOXXXX" ? "PASS" : "FAIL") "`n"
- randomMap := genMap()
- treeCount := countTrees(randomMap)
- OutputDebug, % "Trees found in trajectory: " treeCount "`n"
- randomMap := genMap(20, 20)
- treeCount := countTrees(randomMap, trajectory)
- OutputDebug, % "Trees found in trajectory: " treeCount " | Trajectory: " trajectory "`n"
- genMap(cols := 11, rows := 11)
- {
- map := []
- loop, % rows
- {
- row := ""
- loop, % cols
- {
- Random, tree, 0, 1
- row .= (tree ? "#" : ".")
- }
- map.Push(row)
- }
- return map
- }
- countTrees(map, ByRef trajectory := "")
- {
- treeCount := 0
- , landPoint := 1
- , trajectory := ""
- , startRow := map.RemoveAt(1)
- , rowLength := StrLen(startRow)
- for i,row in map
- {
- landPoint += 3
- if (landPoint > rowLength)
- {
- landPoint := (landPoint - rowLength)
- }
- if (SubStr(row, landPoint, 1) = "#")
- {
- treeCount++
- , trajectory .= "X"
- }
- else
- {
- trajectory .= "O"
- }
- }
- return treeCount
- }
Add Comment
Please, Sign In to add comment