Piet, 120 Codels
Com codelsize 20:
Notas / Como funciona?
Como não é possível usar uma matriz ou string como entrada, esse programa funciona usando uma série de números inteiros (representando caracteres ascii) como entradas. Pensei em usar as entradas de caracteres no início, mas lutei para encontrar uma boa solução para a terminação, então agora termina quando qualquer número menor que 1 é inserido. Originalmente, eram apenas valores negativos para finalização, mas tive que alterar a inicialização após escrever o programa, agora não posso ajustar o necessário 2
, apenas um 1
(26/45 na imagem de rastreamento). Isso não importa, porque de acordo com as regras do desafio, apenas caracteres ascii imprimíveis são permitidos.
Durante muito tempo, lutei para reinserir o loop, apesar de eu ter encontrado a solução bastante elegante no final. Sem pointer
ou switch
operações, apenas o intérprete correr em paredes até que ele transições de volta para a CODEL verde para ler a entrada (43-> 44 nas imagens traço).
A terminação do loop é obtida duplicando primeiro a entrada, adicionando 1 e depois verificando se é maior que 1. Se for, o seletor de codel é acionado e a execução continua no caminho inferior. Caso contrário, o programa continua à esquerda (codelos amarelos brilhantes, 31/50 nas imagens de rastreamento).
O tamanho da entrada suportada depende da implementação do intérprete, embora seja possível suportar uma entrada arbitrariamente grande com o intérprete correto (por exemplo, um intérprete Java que use BigInteger
como valores internos)
Só vi que a configuração inclui um desnecessário DUP
e CC
(7-> 8-> 9 nas imagens de rastreamento). Não faço ideia de como isso aconteceu. Este é efetivamente um noop, porém, alterna o seletor de codel 16 vezes, o que resulta em nenhuma alteração.
Imagens de rastreamento Npiet
Configuração e primeiro loop:
Terminação, saída e saída do loop:
Saídas
Perdoe-me se eu incluir apenas uma saída, leva muito tempo para inserir: ^)
String: "Eagles are great!"
PS B:\Marvin\Desktop\Piet> .\npiet.exe adler32.png
? 69
? 97
? 103
? 108
? 101
? 115
? 32
? 97
? 114
? 101
? 32
? 103
? 114
? 101
? 97
? 116
? 33
? -1
918816254
Rastreio de Npiet para [65, -1]
trace: step 0 (0,0/r,l nR -> 1,0/r,l dR):
action: push, value 4
trace: stack (1 values): 4
trace: step 1 (1,0/r,l dR -> 2,0/r,l dB):
action: duplicate
trace: stack (2 values): 4 4
trace: step 2 (2,0/r,l dB -> 3,0/r,l nM):
action: multiply
trace: stack (1 values): 16
trace: step 3 (3,0/r,l nM -> 4,0/r,l nC):
action: duplicate
trace: stack (2 values): 16 16
trace: step 4 (4,0/r,l nC -> 5,0/r,l nY):
action: duplicate
trace: stack (3 values): 16 16 16
trace: step 5 (5,0/r,l nY -> 6,0/r,l nM):
action: duplicate
trace: stack (4 values): 16 16 16 16
trace: step 6 (6,0/r,l nM -> 7,0/r,l nC):
action: duplicate
trace: stack (5 values): 16 16 16 16 16
trace: step 7 (7,0/r,l nC -> 8,0/r,l nY):
action: duplicate
trace: stack (6 values): 16 16 16 16 16 16
trace: step 8 (8,0/r,l nY -> 9,0/r,l lB):
action: switch
trace: stack (5 values): 16 16 16 16 16
trace: stack (5 values): 16 16 16 16 16
trace: step 9 (9,0/r,l lB -> 10,0/r,l dM):
action: multiply
trace: stack (4 values): 256 16 16 16
trace: step 10 (10,0/r,l dM -> 11,0/r,l nR):
action: multiply
trace: stack (3 values): 4096 16 16
trace: step 11 (11,0/r,l nR -> 12,0/r,l lY):
action: multiply
trace: stack (2 values): 65536 16
trace: step 12 (12,0/r,l lY -> 13,0/r,l lM):
action: duplicate
trace: stack (3 values): 65536 65536 16
trace: step 13 (13,0/r,l lM -> 14,0/r,l nM):
action: push, value 3
trace: stack (4 values): 3 65536 65536 16
trace: step 14 (14,0/r,l nM -> 15,0/r,l dM):
action: push, value 2
trace: stack (5 values): 2 3 65536 65536 16
trace: step 15 (15,0/r,l dM -> 16,0/r,l lC):
action: roll
trace: stack (3 values): 16 65536 65536
trace: step 16 (16,0/r,l lC -> 17,0/r,l nB):
action: sub
trace: stack (2 values): 65520 65536
trace: step 17 (17,0/r,l nB -> 18,0/r,l dB):
action: push, value 1
trace: stack (3 values): 1 65520 65536
trace: step 18 (18,0/r,l dB -> 19,0/r,l dM):
action: add
trace: stack (2 values): 65521 65536
trace: step 19 (19,0/r,l dM -> 19,1/d,r dC):
action: duplicate
trace: stack (3 values): 65521 65521 65536
trace: step 20 (19,1/d,r dC -> 18,1/l,l lC):
action: push, value 1
trace: stack (4 values): 1 65521 65521 65536
trace: step 21 (18,1/l,l lC -> 17,1/l,l nC):
action: push, value 1
trace: stack (5 values): 1 1 65521 65521 65536
trace: step 22 (17,1/l,l nC -> 16,1/l,l dB):
action: sub
trace: stack (4 values): 0 65521 65521 65536
trace: step 23 (16,1/l,l dB -> 15,1/l,l lB):
action: push, value 1
trace: stack (5 values): 1 0 65521 65521 65536
trace: step 24 (15,1/l,l lB -> 13,2/l,l dG):
action: in(number)
? 65
trace: stack (6 values): 65 1 0 65521 65521 65536
trace: step 25 (13,2/l,l dG -> 12,2/l,l dR):
action: duplicate
trace: stack (7 values): 65 65 1 0 65521 65521 65536
trace: step 26 (12,2/l,l dR -> 11,2/l,l lR):
action: push, value 1
trace: stack (8 values): 1 65 65 1 0 65521 65521 65536
trace: step 27 (11,2/l,l lR -> 10,2/l,l lY):
action: add
trace: stack (7 values): 66 65 1 0 65521 65521 65536
trace: step 28 (10,2/l,l lY -> 9,2/l,l nY):
action: push, value 1
trace: stack (8 values): 1 66 65 1 0 65521 65521 65536
trace: step 29 (9,2/l,l nY -> 8,1/l,r nB):
action: greater
trace: stack (7 values): 1 65 1 0 65521 65521 65536
trace: step 30 (8,1/l,r nB -> 7,1/l,r lY):
action: switch
trace: stack (6 values): 65 1 0 65521 65521 65536
trace: stack (6 values): 65 1 0 65521 65521 65536
trace: step 31 (7,1/l,l lY -> 6,2/l,l nY):
action: push, value 2
trace: stack (7 values): 2 65 1 0 65521 65521 65536
trace: step 32 (6,2/l,l nY -> 5,3/l,l dB):
action: pointer
trace: stack (6 values): 65 1 0 65521 65521 65536
trace: step 33 (5,3/r,l dB -> 7,4/r,l dM):
action: add
trace: stack (5 values): 66 0 65521 65521 65536
trace: step 34 (7,4/r,l dM -> 8,4/r,l dC):
action: duplicate
trace: stack (6 values): 66 66 0 65521 65521 65536
trace: step 35 (8,4/r,l dC -> 9,3/r,l lC):
action: push, value 3
trace: stack (7 values): 3 66 66 0 65521 65521 65536
trace: step 36 (9,3/r,l lC -> 10,3/r,l nC):
action: push, value 2
trace: stack (8 values): 2 3 66 66 0 65521 65521 65536
trace: step 37 (10,3/r,l nC -> 11,3/r,l dY):
action: roll
trace: stack (6 values): 0 66 66 65521 65521 65536
trace: step 38 (11,3/r,l dY -> 12,3/r,l dG):
action: add
trace: stack (5 values): 66 66 65521 65521 65536
trace: step 39 (12,3/r,l dG -> 13,3/r,l lG):
action: push, value 2
trace: stack (6 values): 2 66 66 65521 65521 65536
trace: step 40 (13,3/r,l lG -> 14,3/r,l nG):
action: push, value 1
trace: stack (7 values): 1 2 66 66 65521 65521 65536
trace: step 41 (14,3/r,l nG -> 15,3/r,l dR):
action: roll
trace: stack (5 values): 66 66 65521 65521 65536
trace: white cell(s) crossed - continuing with no command at 17,3...
trace: step 42 (15,3/r,l dR -> 17,3/r,l lB):
trace: step 43 (17,3/r,l lB -> 13,2/l,l dG):
action: in(number)
? -1
trace: stack (6 values): -1 66 66 65521 65521 65536
trace: step 44 (13,2/l,l dG -> 12,2/l,l dR):
action: duplicate
trace: stack (7 values): -1 -1 66 66 65521 65521 65536
trace: step 45 (12,2/l,l dR -> 11,2/l,l lR):
action: push, value 1
trace: stack (8 values): 1 -1 -1 66 66 65521 65521 65536
trace: step 46 (11,2/l,l lR -> 10,2/l,l lY):
action: add
trace: stack (7 values): 0 -1 66 66 65521 65521 65536
trace: step 47 (10,2/l,l lY -> 9,2/l,l nY):
action: push, value 1
trace: stack (8 values): 1 0 -1 66 66 65521 65521 65536
trace: step 48 (9,2/l,l nY -> 8,1/l,r nB):
action: greater
trace: stack (7 values): 0 -1 66 66 65521 65521 65536
trace: step 49 (8,1/l,r nB -> 7,1/l,r lY):
action: switch
trace: stack (6 values): -1 66 66 65521 65521 65536
trace: stack (6 values): -1 66 66 65521 65521 65536
trace: step 50 (7,1/l,r lY -> 6,1/l,r dY):
action: pop
trace: stack (5 values): 66 66 65521 65521 65536
trace: step 51 (6,1/l,r dY -> 4,1/l,r lY):
action: push, value 3
trace: stack (6 values): 3 66 66 65521 65521 65536
trace: step 52 (4,1/l,r lY -> 3,1/l,r nY):
action: push, value 2
trace: stack (7 values): 2 3 66 66 65521 65521 65536
trace: step 53 (3,1/l,r nY -> 2,1/l,r nM):
action: duplicate
trace: stack (8 values): 2 2 3 66 66 65521 65521 65536
trace: step 54 (2,1/l,r nM -> 1,1/l,r dG):
action: pointer
trace: stack (7 values): 2 3 66 66 65521 65521 65536
trace: step 55 (1,1/r,r dG -> 2,2/r,r lR):
action: roll
trace: stack (5 values): 65521 66 66 65521 65536
trace: step 56 (2,2/r,r lR -> 2,3/d,l nR):
action: push, value 1
trace: stack (6 values): 1 65521 66 66 65521 65536
trace: step 57 (2,3/d,l nR -> 2,4/d,l lC):
action: switch
trace: stack (5 values): 65521 66 66 65521 65536
trace: stack (5 values): 65521 66 66 65521 65536
trace: step 58 (2,4/d,r lC -> 2,5/d,r nM):
action: mod
trace: stack (4 values): 66 66 65521 65536
trace: step 59 (2,5/d,r nM -> 4,5/r,r dM):
action: push, value 3
trace: stack (5 values): 3 66 66 65521 65536
trace: step 60 (4,5/r,r dM -> 6,5/r,r lM):
action: push, value 2
trace: stack (6 values): 2 3 66 66 65521 65536
trace: step 61 (6,5/r,r lM -> 7,5/r,r nC):
action: roll
trace: stack (4 values): 65521 66 66 65536
trace: step 62 (7,5/r,r nC -> 8,5/r,r dM):
action: mod
trace: stack (3 values): 66 66 65536
trace: step 63 (8,5/r,r dM -> 11,5/r,r lM):
action: push, value 3
trace: stack (4 values): 3 66 66 65536
trace: step 64 (11,5/r,r lM -> 12,5/r,r nM):
action: push, value 1
trace: stack (5 values): 1 3 66 66 65536
trace: step 65 (12,5/r,r nM -> 13,5/r,r dC):
action: roll
trace: stack (3 values): 66 65536 66
trace: step 66 (13,5/r,r dC -> 14,5/r,r nB):
action: multiply
trace: stack (2 values): 4325376 66
trace: step 67 (14,5/r,r nB -> 15,5/r,r nM):
action: add
trace: stack (1 values): 4325442
trace: step 68 (15,5/r,r nM -> 16,5/r,r dB):
action: out(number)
4325442
trace: stack is empty
trace: white cell(s) crossed - continuing with no command at 19,5...
trace: step 69 (16,5/r,r dB -> 19,5/r,r nM):