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

AlephSquirrel
AlephSquirrel
This suggestion will automatically be accepted if it gets enough 👍
rejected

Suggestion to edit judge

Output
Expected
(async function* (context: Context): Challenge { (async function* (context: Context): Challenge { context.code = context.code.replaceAll("\r\n", "\n"); context.code = context.code.replaceAll("\r\n", "\n").replaceAll("\r", "\n"); const asciiOnly = [...context.code].every((x) => x.codePointAt(0) < 128); const asciiOnly = [...context.code].every((x) => x.codePointAt(0) < 128);
AlephSquirrel
AlephSquirrel

I didn’t realize I could just edit directly, please downvote this

AlephSquirrel
AlephSquirrel
This suggestion will automatically be accepted if it gets enough 👍
accepted

Suggestion to edit judge

Output
Expected
1 identical lines skipped 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) { 5 identical lines skipped 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) { 2 identical lines skipped 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) )}.`, )}.`, 4 identical lines skipped 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$/, "");