Byte Heist Home Leaderboard
Join the Heist (with Github)
Solve View

Radiation Resistant Integers Generator

For each integer from 1 to 100, output on a single line a radiation-safe expression (in the same language as your solution) which evaluates to that integer. Radiation-safety refers to the ability to evaluate to the same value even if any single character is removed.

You are writing a full program whose source does not have any restrictions. The output of the program is what is checked for radiation resistance.

Judge

(async function* (context: Context): Challenge {
  if (context.code === "Orthoplex is cool! ".repeat(500)) return context.noFailures();
  type Lang = "Rust" | "Python" | "Javascript";
  async function detectLang(): Promise<Lang | undefined> {
    const runRes = await context.runCode(`fn main() {println!("Rust");}`);
    if (runRes.text.includes("Rust")) return "Rust"
    if (runRes.error().text.includes("invalid syntax")) return "Python"
    if (runRes.error().text.includes("Unexpected identifier")) return "Javascript"
  }
  function expressionToPrint(expr: string, lang: Lang): string {
    return {
      Rust: `println!("{}", ${expr});`,
      Python: `print(eval(${JSON.stringify(expr)}));`,
      Javascript: `console.log(eval(${JSON.stringify(expr)}));`,
    }[lang];
  }
  function expressionsToProgram(exprs: string[], lang: Lang): string {
    const prints = exprs.map((x) => expressionToPrint(x, lang));
    return {
      Rust: `fn main(){${prints.join("")}}`,
      Python: prints.join(""),
      Javascript: prints.join(""),
    }[lang];
  }

  const lang = await detectLang();
  if (lang === undefined) {
    yield context.registerTestCase(new TestCase("Lang detection", "Fail", {
      Text: `Sorry, could not detect the language.`,
    }));
    return context.noFailures();
  }
  yield context.registerTestCase(new TestCase("Lang", "Info", {
      Text: `Detected language: ${lang}.`,
  }));

  const output = (await context.run()).text.trim();
  const asciiOnly = [...output].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 exprs = output.replaceAll("\r\n", "\n").split("\n");

  if (exprs.length !== 100) {
    yield context.registerTestCase(new TestCase("Expressions count", "Fail", {
      Text: `Expected 100 expressions, found ${exprs.length}.`,
    }));
    return context.noFailures();
  }

  const tests = exprs.flatMap((expr, i) =>
    [...expr].map((_, radiatedIndex) => ({
      integer: (i + 1).toString(),
      nonce: rand(101, 1000).toString(),
      expr,
      radiatedIndex,
      radiatedExpr:
        expr.slice(0, radiatedIndex) + expr.slice(radiatedIndex + 1),
    }))
  );
  shuffle(tests);

  for (const test of tests.slice(0, 5)) {
    yield (await context.runCode(expressionsToProgram([test.radiatedExpr], lang)))
      .assertEquals(test.integer)
      .setName(`${test.integer} with char ${test.radiatedIndex} radiated: ${test.radiatedExpr}`);
  }

  if (!context.noFailures().pass) {
    return context.noFailures();
  }

  const program = expressionsToProgram(
    tests.flatMap((x) => [x.radiatedExpr, x.nonce]),
    lang
  );
  const expectedOutput = tests.flatMap((x) => [x.integer, x.nonce]).join("\n");
  const result = (await context.runCode(program))
    .assertEquals(expectedOutput)
    .setName(`Omnicase`);
  if (result.pass === "Pass") {
    result.resultDisplay = { Text: "Pass" };
  }
  yield result;
  return context.noFailures();
});

Example Code

Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool! Orthoplex is cool!