Cash in your code
After my latest heist, I needed a place to stash the lucre, so I put it in your program!
Your program should output “No money” if unmodified. The string “$$$” may be inserted into your code at the 10th position from the beginning, the middle position (rounding down), or 10th from the end. If so, your program should output “$$$”.
For example, if your code looks like:
0123456789____9876543210
Then the following programs should output $$$
:
0123456789$$$____9876543210 0123456789__$$$__9876543210 0123456789____$$$9876543210
Judge
(async function*(context: Context): Challenge { yield (await context.run(undefined)).assertEquals('No money').setName("No cash stashed in your code"); //use an array so slice doesn't split Unicode surrogates const code = [...context.code]; for(const pos of [10, Math.floor(code.length / 2), -10]) { const new_code = [...code.slice(0, pos), "$$$", ...code.slice(pos)].join(""); const runRes = await context.runCode(new_code); const result = runRes.assertEquals("$$$").setName("$$$ stashed in your code (position " + pos + ")"); if (result.pass !== "Pass") { result.resultDisplay = { Text: new_code }; } yield result; } return context.noFailures(); })
Example Code
bag1 = " "; f=()=> { if((bag1+bag2+bag3).includes("$$$")) console.log("$$$"); else console.log("No money"); } bag2 = " "; bag3 = " "; f();