[2021 Day 24 Part 1] Visualization of checking submarine number (spoilers)
imgur.com/a/WE1QEEoPosted Dec 25, 2021, 4:21 AM UTC
245
Posted Dec 25, 2021, 4:21 AM UTC
Cool visualisation! I liked the table formatting. What did you use to make this?
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)
ooh, what a great resource! thanks for sharing
I found this handy too https://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html
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
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.