Last active
August 16, 2024 19:38
-
-
Save septor/62ebdec14f221e787a068374822ca5cf to your computer and use it in GitHub Desktop.
Cherrytree Vault Code Generator
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
const fs = require('fs'); | |
const digits = "45689".split(""); | |
const length = 7; | |
function generateCombinations(digits, length, filePath) { | |
const combinations = []; | |
const recursiveGenerate = (prefix, remainingLength, usedDigits) => { | |
if (remainingLength === 0) { | |
if (usedDigits.size === digits.length) { | |
combinations.push(prefix.trim()); | |
} | |
return; | |
} | |
for (let digit of digits) { | |
let newPrefix; | |
if (remainingLength > 1) { | |
newPrefix = prefix + digit + " "; | |
} else { | |
newPrefix = prefix + digit; | |
} | |
let newUsedDigits = new Set(usedDigits); | |
newUsedDigits.add(digit); | |
recursiveGenerate(newPrefix, remainingLength - 1, newUsedDigits); | |
} | |
}; | |
recursiveGenerate("", length, new Set()); | |
fs.writeFile(filePath, combinations.join('\n'), (err) => { | |
if (err) { | |
console.error('Error writing to file:', err); | |
} else { | |
console.log('Combinations have been written to', filePath); | |
} | |
}); | |
} | |
const filePath = "combinations.txt"; | |
generateCombinations(digits, length, filePath); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment