TIS-100, 413 405 octets
472 cycles, 5 nœuds, 35 lignes de code
m4,6
@0
MOV 0 ANY
S:MOV UP ACC
JEZ A
MOV ACC ANY
JMP S
A:MOV RIGHT ACC
L:JEZ B
MOV DOWN NIL
SUB 1
JMP L
B:MOV 0 RIGHT
MOV RIGHT NIL
@1
MOV RIGHT LEFT
MOV LEFT DOWN
MOV RIGHT DOWN
MOV DOWN LEFT
@2
MOV UP ACC
MOV UP LEFT
MOV ACC LEFT
@4
MOV 0 RIGHT
MOV UP NIL
S:MOV LEFT ACC
JEZ A
MOV ACC RIGHT
JMP S
A:MOV UP ACC
L:JEZ B
MOV RIGHT NIL
SUB 1
JMP L
B:MOV 0 UP
K:MOV RIGHT ACC
MOV ACC DOWN
JNZ K
@7
MOV UP ANY
Le m4,6 en haut ne fait pas partie du code, mais signale le placement des modules de mémoire.
Jouez ce niveau vous-même en le collant dans le jeu:
function get_name()
return "ARRAY TRIMMER"
end
function get_description()
return { "RECIEVE AN ARRAY FROM IN.A", "RECIEVE TWO VALUES A THEN B FROM IN.T", "REMOVE THE FIRST A TERMS AND LAST B TERMS FROM IN.A", "ARRAYS ARE 0 TERMINATED" }
end
function get_streams()
input = {}
trim = {}
output = {}
arrayLengths = {}
a = math.random(1,5) - 3
b = math.random(1,7) - 4
arrayLengths[1] = 9+a
arrayLengths[2] = 9+b
arrayLengths[3] = 8-a
arrayLengths[4] = 9-b
s = 0
trimIndex = 1
for i = 1,4 do
for k = 1,arrayLengths[i] do
x = math.random(1,999)
input[k+s] = x
output[k+s] = x
end
input[s + arrayLengths[i] + 1]= 0
output[s + arrayLengths[i] + 1]= 0
a = math.random(0,3)
b = math.random(0,arrayLengths[i]-a)
trim[trimIndex] = a
trim[trimIndex+1] = b
trimIndex = trimIndex + 2
s = s + arrayLengths[i] + 1
end
s = 1
trimIndex = 1
for i = 1,4 do
for i = s,s+trim[trimIndex]-1 do
output[i]=-99
end
for i = s + arrayLengths[i] - trim[trimIndex+1], s + arrayLengths[i]-1 do
output[i]=-99
end
trimIndex = trimIndex +2
s = s + arrayLengths[i] + 1
end
trimmedOut = {}
for i = 1,39 do
if(output[i] ~= -99) then
table.insert(trimmedOut, output[i])
end
end
return {
{ STREAM_INPUT, "IN.A", 0, input },
{ STREAM_INPUT, "IN.T", 2, trim },
{ STREAM_OUTPUT, "OUT.A", 1, trimmedOut },
}
end
function get_layout()
return {
TILE_COMPUTE, TILE_COMPUTE, TILE_COMPUTE, TILE_COMPUTE,
TILE_MEMORY, TILE_COMPUTE, TILE_MEMORY, TILE_COMPUTE,
TILE_COMPUTE, TILE_COMPUTE, TILE_COMPUTE, TILE_COMPUTE,
}
end
Donc je suppose que cela compte aussi comme une réponse lua ...