morolinOP•

Wanted to make sure the engine I made to execute the language didn't go completely to waste. :)

Included the translation into pseudo-code that i used to understand each one of the digit checks, but that's probably a spoiler for those who haven't figured it out yet.

2
kylynx•

Cool visualisation! I liked the table formatting. What did you use to make this?

1
morolinOP•

Just Python with some terminal control characters and copy-paste from the Wikipedia Box-drawing character page. :)

https://en.wikipedia.org/wiki/Box-drawing_character

def show(n, prog, trans, regs, inp, pc, done):
    zlist = []
    zr = regs['z']
    while zr != 0:
        zlist.append(zr % 26)
        zr //= 26
    if pc is not None:
        cache = prog[pc]
        prog[pc] = u"\u001b[47m\u001b[38;5;0m{: <9}\u001b[0m".format(prog[pc])
    outp = ["\033[H"]
    outp.append("Checking digit: {}".format(n+1))
    outp.append("  ╔═══════════╦═══════════╗")
    outp.append("  ║ {: <9} ║ {: <9} ║  input: {: <14}   ".format(prog[0], prog[9], "".join(map(str, inp))))
    outp.append("  ║ {: <9} ║ {: <9} ║      w: {}        ".format(prog[1], prog[10], regs['w']))
    outp.append("  ║ {: <9} ║ {: <9} ║      x: {}        ".format(prog[2], prog[11], regs['x']))
    outp.append("  ║ {: <9} ║ {: <9} ║      y: {}        ".format(prog[3], prog[12], regs['y']))
    outp.append("  ║ {: <9} ║ {: <9} ║      z: {} ({}) {}     ".format(prog[4], prog[13], regs['z'], zlist, "✓ ok" if done else ""))
    outp.append("  ║ {: <9} ║ {: <9} ║".format(prog[5], prog[14]))
    outp.append("  ║ {: <9} ║ {: <9} ║  Translation:".format(prog[6], prog[15]))
    outp.append("  ║ {: <9} ║ {: <9} ║    x = {} z    ".format(prog[7], prog[16], 'pop' if trans[0] else 'head'))
    outp.append("  ║ {: <9} ║ {: <9} ║    if x {} {} == w:     ".format(prog[8], prog[17], '-' if trans[2] < 0 else '+', abs(trans[2]) ))
    outp.append("  ╚═══════════╩═══════════╝      push z (w + {})     ".format(trans[1]))
    if pc is not None:
        prog[pc] = cache
    return "\n".join(outp)
1
kylynx•

ooh, what a great resource! thanks for sharing

1
timgfx•

How did you find these numbers with the stack approach? I have made a DP brute force solution and am currently working on a stack solution

1