...at least for some definition of "self-modification".
In this challenge, your task is to write three strings
C that satisfy the following properties.
Bhas length at least 1.
n ≥ 0, the string
ABnCis a valid program (meaning full runnable program or function definition) in your programming language of choice. The superscript denotes repetition, so this means the strings
ABBBCetc. Each program takes one string as input, and returns one string as output.
m, n ≥ 0, if the program
ABmCis run with input
ABnC, it returns
ABm*n+1C. For inputs not of this form, the program may do anything, including crash.
Some examples in the format
program(input) -> output:
AC(AC) -> ABC ABC(AC) -> ABC ABBBBBC(AC) -> ABC AC(ABC) -> ABC AC(ABBBBC) -> ABC ABC(ABC) -> ABBC ABBC(ABC) -> ABBBC ABBBBC(ABBBC) -> ABBBBBBBBBBBBBC ABBBC(ABBBBBBC) -> ABBBBBBBBBBBBBBBBBBBC
Rules and Scoring
Your score is the total length of
C, lower score being better.
Note that while
B is not counted toward the score, it must be produced by
C as in the first example.
Standard loopholes are disallowed.
The programs are not allowed to directly or indirectly access their own source code (except when they are given it as input).
You are required to identify the strings
C in your answer in some way, and encouraged to explain your solution.