modularity

This commit is contained in:
2025-09-30 14:20:50 +02:00
parent c16b3738ea
commit 304627b248
26 changed files with 892 additions and 198 deletions

View File

@ -40,23 +40,10 @@ const TEMPLATES: Template[] = [
{ pattern: "((t>>S1)|(t>>S2))&((t>>S3)|(t>>S4))", weight: 6 }
]
const TOTAL_WEIGHT = TEMPLATES.reduce((sum, t) => sum + t.weight, 0)
function randomElement<T>(arr: T[]): T {
return arr[Math.floor(Math.random() * arr.length)]
}
function pickTemplate(): Template {
let random = Math.random() * TOTAL_WEIGHT
for (const template of TEMPLATES) {
random -= template.weight
if (random <= 0) {
return template
}
}
return TEMPLATES[0]
}
function fillTemplate(pattern: string): string {
let formula = pattern