Omniperiodicity
Description
In 2023 it was proven that the Game of life is omniperiodic, meaning that there exists patterns that repeat for the first time after some n steps for every n. This fact was proven only after the discovery of a period-41 oscillator, the final period that needed to be found.
Today your task is to prove that your programming language of choice is omioperiodic, which thankfully only requires you to provide a period-41 oscillator. That is, your program must print the string period-41 exactly once whenever the program is repeated some multiple of 41 times, and not print anything for any other number of repetitions.
For example, if your program was abc, the program abc by itself must not print anything, but the program abcabcabc… (“abc” repeated 41 times) must print period-41. Likewise, “abc” repeated 82 times must also print period-41 exactly once.
Your score will be the length of your code in bytes multiplied by 41 :)
Judge
(async function*(context: Context): Challenge { const codeLength = new TextEncoder('utf-8').encode(context.code).length; if (codeLength > 100) { yield (context.registerTestCase(new TestCase('Code length', 'Fail', {'Text': 'Solution too long to test, please shorten.'}))); return context.noFailures(); } const MAX_CODE_LEN = 8200; const MAX_REPETITION = MAX_CODE_LEN / 100; yield (await context.run()).assertEquals('').setName('repetition 1'); for (let i = 41; i <= MAX_REPETITION; i += 41) { yield (await context.runCode(context.code.repeat(i))).assertEquals('period-41').setName(`repetition ${i}`) } for (let _ = 0; _ <= 10; _++) { // generate a test case not divisible by 41 let i = Math.floor(Math.random() * MAX_REPETITION); if (i % 41 == 0) i++; // fun fact there is a formula for the nth number not divisible by 41, ⌊(41x-1)/40⌋ yield (await context.runCode(context.code.repeat(i))).assertEquals('').setName(`repetition ${i}`); } return context.noFailures(codeLength * 41); })
Example Code
7 i='i'in globalThis?i+1:1; ({set b(v){if (v!=77 && i%41==0){console.log('period-41') }}}).b=7
Comments
To prevent cheese, need to have a guaranteed test for 41<n<82
Suggestion to edit judge