Guest User

Untitled

a guest
Dec 17th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SetWorkingDir %A_ScriptDir%
  2.  
  3. FileRead, cubesStr, % A_ScriptDir "\d17.txt"
  4.  
  5. cubesStr := StrReplace(cubesStr, "#", 1)
  6. cubesStr := StrReplace(cubesStr, ".", 0)
  7.  
  8. nei := []
  9. Loop, 3
  10. {
  11.     x := A_Index - 2
  12.     Loop, 3
  13.     {
  14.         y := A_Index - 2
  15.         Loop, 3
  16.         {
  17.             z := A_Index - 2
  18.             Loop, 3
  19.             {
  20.                 w := A_Index - 2
  21.                 if (x = 0) and (y = 0) and (z = 0) and (w = 0)
  22.                     Continue
  23.                 nei.Push({x: x, y: y, z: z, w: w})
  24.             }
  25.         }
  26.     }
  27. }
  28.  
  29. cubes := []
  30. cubes[0] := StrSplit(cubesStr, "`r`n")
  31. for i, j in cubes[0] {
  32.     cubes[0][i] := []
  33.     for k, l in StrSplit(j) {
  34.         if !cubes[0][i][k] {
  35.             cubes[0][i][k] := []
  36.         }
  37.         cubes[0][i][k][0] := {}
  38.         cubes[0][i][k][0]["state"] := l
  39.         cubes[0][i][k][0]["actN"] := 0
  40.         cubes[0][i][k][0]["inaN"] := 0
  41.     }
  42. }
  43.  
  44. Loop, 6
  45. {
  46.     cubesC := ObjFullyClone(cubes)
  47.     for z, layer in cubesC {
  48.         for y, line in layer {
  49.             for x, cell in line {
  50.                 for w, cube in cell {
  51.                     for a, neiC in GetCubesNei(nei, x, y, z, w) {
  52.                         if !cubes[neiC.z]
  53.                             cubes[neiC.z] := []
  54.                         if !cubes[neiC.z][neiC.y]
  55.                             cubes[neiC.z][neiC.y] := []
  56.                         if !cubes[neiC.z][neiC.y][neiC.x]
  57.                             cubes[neiC.z][neiC.y][neiC.x] := []
  58.                         if !cubes[neiC.z][neiC.y][neiC.x][neiC.w] {
  59.                             cubes[neiC.z][neiC.y][neiC.x][neiC.w] := {}
  60.                             cubes[neiC.z][neiC.y][neiC.x][neiC.w]["state"] := 0
  61.                             cubes[neiC.z][neiC.y][neiC.x][neiC.w]["actN"] := 0
  62.                             cubes[neiC.z][neiC.y][neiC.x][neiC.w]["inaN"] := 0
  63.                         }
  64.                         if (cube.state = 1)
  65.                             cubes[neiC.z][neiC.y][neiC.x][neiC.w]["actN"] += 1
  66.                         else
  67.                             cubes[neiC.z][neiC.y][neiC.x][neiC.w]["inaN"] += 1
  68.                     }
  69.                 }
  70.             }
  71.         }
  72.     }
  73.  
  74.     for z, layer in cubes {
  75.         for y, line in layer {
  76.             for x, cell in line {
  77.                 for w, cube in cell {
  78.                     if (cube.state = 1) and ((cube.actN != 2) and (cube.actN != 3))
  79.                         cubes[z][y][x][w]["state"] := 0
  80.                     if (cube.state = 0) and (cube.actN = 3)
  81.                         cubes[z][y][x][w]["state"] := 1
  82.                     cubes[z][y][x][w]["actN"] := 0
  83.                     cubes[z][y][x][w]["inaN"] := 0
  84.                 }
  85.             }
  86.         }
  87.     }
  88.  
  89.     cubesC := ""
  90. }
  91.  
  92. activeCount := 0
  93.  
  94. for z, layer in cubes {
  95.     for y, line in layer {
  96.         for x, cell in line {
  97.             for w, cube in cell {
  98.                 if (cube.state = 1)
  99.                     activeCount += 1
  100.             }
  101.         }
  102.     }
  103. }
  104.  
  105. Clipboard := activeCount
  106.  
  107. GetCubesNei(nei, x, y, z, w) {
  108.     CubesNei := []
  109.     for i, j in nei {
  110.         CubesNei.Push({x: j.x + x, y: j.y + y, z: j.z + z, w: j.w + w})
  111.     }
  112.     Return CubesNei
  113. }
  114.  
  115. ObjFullyClone(obj) {
  116.     nobj := obj.Clone()
  117.     for k,v in nobj
  118.         if IsObject(v)
  119.             nobj[k] := A_ThisFunc.(v)
  120.     return nobj
  121. }
Advertisement
Add Comment
Please, Sign In to add comment