Diagonal Symmetry Quine
Write a code that is a square symmetrical along the main diagonal and which prints the diagonal. The output is whitespace sensitive, but trailing newline is optional.
Judge
(async function* (context: Context): Challenge { context.code = context.code.replaceAll("\r\n", "\n"); 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 lines = context.code.split("\n"); const isSquare = lines.every((x) => x.length === lines.length); if (!isSquare) { yield context.registerTestCase( new TestCase("Square", "Fail", { Text: `Expected square but found lines of lengths ${JSON.stringify( lines.map((x) => x.length) )}.`, }) ); return context.noFailures(); } const diagonal = lines.map((x, i) => x[i]).join(""); const transposed = lines .map((_, i) => lines.map((_, j) => lines[j][i]).join("")) .join("\n"); yield context.registerTestCase( new TestCase("Symmetry", context.code === transposed ? "Pass" : "Fail", { Diff: { expected: context.code, output: transposed }, }) ); const output = (await context.run()).text.replace(/\r?\n$/, ""); yield context.registerTestCase( new TestCase("Diagonal", diagonal === output ? "Pass" : "Fail", { Diff: { expected: diagonal, output }, }) ); return context.noFailures(); });
Example Code
//////////////////////////////// /**/console.log("/*".padEnd(32)) /* * // / /c /o /n /s /o /l /e /. /l /o /g /( /" // /* /" /. /p /a /d /E /n /d /( /3 /2 /) /)*/