...at least for some definition of "self-modification".
The Task
In this challenge, your task is to write three strings A
, B
and C
that satisfy the following properties.
The string
B
has length at least 1.For every
n ≥ 0
, the stringABnC
is a valid program (meaning full runnable program or function definition) in your programming language of choice. The superscript denotes repetition, so this means the stringsAC
,ABC
,ABBC
,ABBBC
etc. Each program takes one string as input, and returns one string as output.For any
m, n ≥ 0
, if the programABmC
is run with inputABnC
, it returnsABm*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 A
and C
, lower score being better.
Note that while B
is not counted toward the score, it must be produced by A
and 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 A
, B
and C
in your answer in some way, and encouraged to explain your solution.