Created
September 18, 2023 08:58
-
-
Save quentint/e25e5aebb87dfa57f6d021beec942c9c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import {encode} from "uqr" | |
let message = 'Lorem' | |
const {data: matrix} = encode(message) | |
function getSafeMatrixItemFlag(matrix: Array<Array<boolean>>, i: number, j: number): boolean { | |
if (!matrix[i]) { | |
return false | |
} | |
return matrix[i][j] || false | |
} | |
function splitBooleanMatrixIntoSubMatrices(matrix: Array<Array<boolean>>, subMatrixWidth: number = 2, subMatrixHeight = 3): boolean[][][] { | |
const subMatrices: boolean[][][] = [] | |
for (let i = 0; i < matrix.length; i += subMatrixWidth) { | |
const subMatrix: boolean[][] = [] | |
for (let j = 0; j < matrix.length; j += subMatrixHeight) { | |
const subSubMatrix: boolean[] = [] | |
for (let k = 0; k < subMatrixWidth; k++) { | |
for (let l = 0; l < subMatrixHeight; l++) { | |
subSubMatrix.push(getSafeMatrixItemFlag(matrix, i + k, j + l)) | |
} | |
} | |
subMatrix.push(subSubMatrix) | |
} | |
subMatrices.push(subMatrix) | |
} | |
return subMatrices | |
} | |
console.log(splitBooleanMatrixIntoSubMatrices(matrix)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment