Created
April 3, 2025 21:57
-
-
Save lethern/475f3bbc71326969c1a83bf4fa2b5d47 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let set = []; | |
play(matrix, depth); | |
function play(matrix, depth){ | |
print(matrix, depth); | |
if(depth == 0) { | |
result(matrix); | |
return; | |
} | |
let moves = 0; | |
for (let i = 0; i < 3; i++) { | |
for (let j = 0; j < 3; j++) { | |
if(matrix[i*3+j] === 0){ | |
check_move([...matrix], i, j, depth) | |
moves++; | |
} | |
} | |
} | |
if(moves === 0){ | |
result(matrix); | |
} | |
} | |
function check_move(matrix, i, j, depth){ | |
let adj = []; | |
if(i >= 1) adj.push(matrix[(i-1)*3+j]) | |
if(i <= 1) adj.push(matrix[(i+1)*3+j]) | |
if(j >= 1) adj.push(matrix[i*3+j-1]) | |
if(j <= 1) adj.push(matrix[i*3+j+1]) | |
let val = adj.reduce((a,b) => a + b); | |
if(adj.length >= 2 && val > 0 && val <= 6){ | |
matrix[i*3+j] = val | |
if(i >= 1) matrix[(i-1)*3+j] = 0; | |
if(i <= 1) matrix[(i+1)*3+j] = 0; | |
if(j >= 1) matrix[i*3+j-1] = 0; | |
if(j <= 1) matrix[i*3+j+1] = 0; | |
}else { | |
matrix[i*3+j] = 1; | |
} | |
play(matrix, depth-1); | |
} | |
function result(matrix){ | |
let val = 0; | |
for(let i of matrix){ | |
val *= 10; | |
val += i; | |
} | |
set.push(val); | |
} | |
let final = 0; | |
for(let s of set){ | |
final = (final + s) % 1073741824; | |
} | |
console.log(final); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment