exec puzzle gauntlet
Description
This challenge consists of multiple puzzles. Each solution should take up exactly one line (you may need to use semicolons).
To admit defeat to a puzzle, submit one hundred hashes (#) in a row as the solution.
Puzzle one
i=100;exec(________________*_)
In the code above, you can replace each underscore with any byte (you can’t replace an underscore with nothing). Can you make the code above print only the integers from 99 to 1, descending?
Puzzle two (orthoplex)
Same set up as problem 1, but additionally your code must not contain the string print.
Puzzle three (Sisyphus)
Format:
i=100;exec(_________________*_)
Output: 99-1 descending, but with 1 printed twice.
Puzzle four (biz)
Format:
i=100;eval(___________________*_)
Print 99-1 descending
Puzzle five (khvdm)
Format
i=1000;exec(__________________*_)
Output: all evens between 999 and 1, descending (998, 996, 994, …, 6, 4, 2)
Puzzle six (khvdm2)
Format
i=1000;exec(_________________*_)
Output: all evens between 999 and -1, descending (998, 996, 994, …, 4, 2, 0)
Judge
(async function*(context: Context): Challenge { const solutions = context.code.split(/\r?\n/); if (solutions.length !== 6) { yield context.registerTestCase( new TestCase("Expressions count", "Fail", { Text: `Expected 6 solutions, found ${solutions.length}.`, }) ); return context.noFailures(); } const asciiOnly = [...context.code].every((x) => x.codePointAt(0)! < 128); if (!asciiOnly) { yield context.registerTestCase( new TestCase("Ascii only", "Fail", { Text: `Expected only ascii characters.`, }) ); return context.noFailures(); } const handleTestcaseFunc = async (matchFunc: (c:string) => boolean, code: string, expectedOutput: string): Promise<TestCase> => { if (matchFunc(code)) { return (await context.runCode(code)).assertEquals(expectedOutput).setName(code); } else { return context.registerTestCase(new TestCase( 'Comment', code === '#'.repeat(100) ? "Pass" : "Fail", {Diff: {expected: '#'.repeat(100), output: code}} )); } }; // Special case const handleTestcaseRegex = async (format: RegExp, code: string, expectedOutput: string): Promise<TestCase> => { return handleTestcaseFunc((c) => !!c.match(format), code, expectedOutput); } // Base challenge yield (await handleTestcaseRegex( /^i=100;exec\(.{0,16}\*.\)$/, solutions[0], range(1, 100).reverse().map(i => i.toString()).join('\n') )); // Orthoplex yield (await handleTestcaseFunc( (code) => !!code.match(/^i=100;exec\(.{0,16}\*.\)$/) && !code.includes('print'), solutions[1], range(1, 100).reverse().map(i => i.toString()).join('\n') )); // Sisyphus yield (await handleTestcaseRegex( /^i=100;exec\(.{0,17}\*.\)$/, solutions[2], range(1, 100).reverse().concat(1).map(i => i.toString()).join('\n') )); // Biz yield (await handleTestcaseRegex( /^i=100;eval\(.{0,19}\*.\)$/, solutions[3], range(1, 100).reverse().map(i => i.toString()).join('\n') )); // khvdm yield (await handleTestcaseRegex( /^i=1000;exec\(.{0,18}\*.\)$/, solutions[4], range(1, 999).reverse().filter(i => i%2 === 0).map(i => i.toString()).join('\n') )); // khvdm 2 yield (await handleTestcaseRegex( /^i=1000;exec\(.{0,17}\*.\)$/, solutions[5], range(0, 999).reverse().filter(i => i%2 === 0).map(i => i.toString()).join('\n') )); return context.noFailures(); })
Example Code
#################################################################################################### #################################################################################################### #################################################################################################### #################################################################################################### #################################################################################################### ####################################################################################################