Skip to content

Instantly share code, notes, and snippets.

@nnnlog
Created January 29, 2022 06:49
Show Gist options
  • Save nnnlog/15b7e3b02509b5def0bed083556d412b to your computer and use it in GitHub Desktop.
Save nnnlog/15b7e3b02509b5def0bed083556d412b to your computer and use it in GitHub Desktop.
BOJ 5015 데추주 제너레이터
const {mt_rand, shuffle} = require("./utils");
module.exports = () => {
let ret = ``;
let sz = mt_rand(1, 100);
while (sz--) {
let c = mt_rand(0, 50);
if (c >= 27) ret += "*";
else if (c === 26) ret += ".";
else ret += `${String.fromCharCode("a".charCodeAt(0) + c)}`;
}
let pattern = ret;
let n = 100;
ret += `\n${n}\n`;
while (n--) {
let nxt = "";
for (let c of pattern) {
if (c !== "*") nxt += c;
else if (mt_rand(0, 1)) nxt += `${String.fromCharCode("a".charCodeAt(0) + mt_rand(0, 25))}`;
}
if (nxt.length === 0) nxt = `${String.fromCharCode("a".charCodeAt(0) + mt_rand(0, 25))}`;
if (mt_rand(0, 1)) {
ret += `${nxt}\n`;
} else {
let pos = mt_rand(0, nxt.length);
if (nxt.length === 100) ret += `${nxt}\n`;
else ret += `${nxt.substr(0, pos) + String.fromCharCode("a".charCodeAt(0) + mt_rand(0, 25)) + nxt.substr(pos)}\n`;
}
}
return ret;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment