Triangle Quine
Description
Write a program that prints out a triangle of * characters of size n, for some number n. This is a triangle of size 3:
*** ** *
Additionally, the program should have the same shape as its output.
Judge
(async function* (context: Context): Challenge { context.code = context.code.replaceAll("\r\n", "\n").replaceAll("\r", "\n"); /* const bmpOnly = [...context.code].every((x) => x.codePointAt(0) < 65536); if (!bmpOnly) { yield context.registerTestCase( new TestCase("BMP only", "Fail", { Text: `Expected only BMP characters.`, }) ); return context.noFailures(); } */ const lines = context.code.split("\n"); const isTriangle = lines.every((x, i) => [...x].length === (lines.length - i)); if (!isTriangle) { yield context.registerTestCase( new TestCase("Program is triangle", "Fail", { Text: `Expected triangle but found lines of lengths ${JSON.stringify( lines.map((x) => [...x].length) )}.`, }) ); return context.noFailures(); } const triangle = context.code.replaceAll(/./gu, "*"); yield (await context.run()).assertEquals(triangle).setName("Output is triangle"); return context.noFailures(); });
Example Code
for(i=41;i;i--)console.log("*".repeat(i)) // / // / // / // / // / // / // / // / // / // / // / // / // / // / // / // / // / // / // / // / // / // / // / // / // / // / // / // / // / // / // / // / // / // / // / // / // / /// // 7
Comments
accepted
Suggestion to edit judge
Output
Expected
context.code = context.code.replaceAll("\r\n", "\n").replaceAll("\r", "\n");
context.code = context.code.replaceAll("\r\n", "\n").replaceAll("\r", "\n");
const bmpOnly = [...context.code].every((x) => x.codePointAt(0) < 65536);
/* const bmpOnly = [...context.code].every((x) => x.codePointAt(0) < 65536);
if (!bmpOnly) {
if (!bmpOnly) {
return context.noFailures();
return context.noFailures();
}
} */
const lines = context.code.split("\n");
const lines = context.code.split("\n");
const isTriangle = lines.every((x, i) => x.length === (lines.length - i));
const isTriangle = lines.every((x, i) => [...x].length === (lines.length - i));
if (!isTriangle) {
if (!isTriangle) {
Text: `Expected triangle but found lines of lengths ${JSON.stringify(
Text: `Expected triangle but found lines of lengths ${JSON.stringify(
lines.map((x) => x.length)
lines.map((x) => [...x].length)
)}.`,
)}.`,
const triangle = context.code.replaceAll(/./g, "*")
const triangle = context.code.replaceAll(/./gu, "*")
const output = (await context.run()).text.replace(/\r?\n$/, "");
const output = (await context.run()).text.replace(/\r?\n$/, "");
Suggestion to edit judge
I didn’t realize I could just edit directly, please downvote this