TovTovTov (a mutation of Chicken): 810147050 bytes
Described below are two suggested solutions: One full solution to the question requiring lots of bytes, and a second partial solution (solving only the N+N and N*N parts, requiring only 484 bytes), each taking a different approach and its own set of cool tricks! :)
1. Full solution (810147050 bytes)
Using TovTovTov(TOV='hi',SEP=',')
, the TOV
elements are immune to duplicating characters in place (both "hihihi"
and "hhiihhiihhii"
have three "hi"
s in them, and all TovTovTov
cares about is how many TOV
s appear between SEP
s).
If we used SEP=', '
, the entire program would be immune to character duplication (which is cool, but won't solve the question). So we use SEP=','
.
So the program "hihihi,hi"
, for example, compiles to the ints array [3,1]
, while "hhiihhiihhii,,hhii"
compiles to [3,0,1]
and "hhiihhiihhii,,hhii"
to [3,0,0,1]
. This means that the commands themselves don't change their meaning after duplication, but the overall length changes with character duplication. The solution below queries the length of the program and uses this to decide whether to print N+N
, N*N
or N^N
.
The suggested full solution, as ints array, is: [6, 12, 9, 18, 9, 142, 11, 38, 8, 9, 260, 11, 73, 8, 22, 75, 7, 10, 14, 3, 1, 22, 24, 18, 15, 8, 10, 16, 3, 1, 22, 24, 18, 15, 8, 10, 45, 16, 7, 22, 3, 1, 22, 24, 18, 15, 8, 22, 3, 1, 22, 24, 18, 15, 8, 25, 3, 1, 22, 24, 18, 15, 8, 48, 3, 1, 22, 24, 18, 15, 8, 277, 3, 1, 22, 24, 18, 15, 8, 3146, 3, 1, 22, 24, 18, 15, 8, 46677, 3, 1, 22, 24, 18, 15, 8, 823564, 3, 1, 22, 24, 18, 15, 8, 16777237, 3, 1, 22, 24, 18, 15, 8, 387420510, 3, 1, 22, 24, 18, 15, 8]
As a string, it's a pretty long program, consisting of 810147050 characters, starting with:
hihihihihihi,hihihihihihihihihihihihi,hihihihihihihihihi,hihihihihihihihihihihihihihihihihihi,hihihihihihihihihi,hihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihih...
2. Solving only the N+N and N*N parts of the question (484 bytes)
Using TovTovTov(TOV='1',SEP=', ')
, this time the SEP
s are immune to duplication (",, "
still has just one ", "
in it), so the following suggested solution will always have 33 commands in it, even after character duplication:
1111, 111111111111111111111111111111111111111111111111, 1111111111, 1111111111, 1111111111, 111111, 111111111111, 111111111, 11111111111111, 111, 1, 1111111111111111111111, 111111111111111111111111, 111111111111111111, 111111111111111, 11111111, 111111111111, 1111111111111111, 111111111111111, 1111111111111111111111, 111111111111111111111111111111111111, 11, 1111111111111111111111111111, 111111, 111, 111111, 11111111111, 111111111111111111111111111, 1111, 1, 11111111, 1, 11111111
The corresponding ints array (the number of TOV
s (1
s) in each of the 33 commands above) is as follows: [4,48,10,10,10,6,12,9,14,3,1,22,24,18,15,8,12,16,15,22,36,2,28,6,3,6,11,27,4,1,8,1,8]
Duplicating the characters in place results in a list of 33 totally different commands:
[8,96,20,20,20,12,24,18,28,6,2,44,48,36,30,16,24,32,30,44,72,4,56,12,6,12,22,54,8,2,16,2,16]
The original ints array (that calculates N+N) was designed carefully so that after the commands change their meaning, the program still makes sense, but calculates N*N. For example, the first 4
(that TovTovTov
understands as "treat the next op as an ascii code to convert to a character") changes after character duplication to 8
, which is a totally different command ("change the Program Counter to the first popped value from the stack, if the value popped immediately after is true").