temporary

This commit is contained in:
2025-09-30 10:56:38 +02:00
commit 95845e8af8
23 changed files with 3414 additions and 0 deletions

View File

@ -0,0 +1,43 @@
const operators = ['&', '|', '^', '+', '-', '*', '%']
const shifts = ['>>', '<<']
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 20, 25, 32, 42, 63, 64, 127, 128, 255]
function randomElement<T>(arr: T[]): T {
return arr[Math.floor(Math.random() * arr.length)]
}
function generateTerm(depth: number = 0): string {
if (depth > 2 || Math.random() < 0.3) {
const shift = randomElement(shifts)
const num = randomElement(numbers)
return `(t${shift}${num})`
}
const op = randomElement(operators)
const left = generateTerm(depth + 1)
const right = Math.random() < 0.5 ? generateTerm(depth + 1) : randomElement(numbers).toString()
return `(${left}${op}${right})`
}
export function generateRandomFormula(): string {
const numTerms = Math.floor(Math.random() * 3) + 1
const terms: string[] = []
for (let i = 0; i < numTerms; i++) {
terms.push(generateTerm())
}
return terms.join(randomElement(operators))
}
export function generateFormulaGrid(rows: number, cols: number): string[][] {
const grid: string[][] = []
for (let i = 0; i < rows; i++) {
const row: string[] = []
for (let j = 0; j < cols; j++) {
row.push(generateRandomFormula())
}
grid.push(row)
}
return grid
}