I also solved this task, and I decided to choose a bit different way. As we have some kind of programming language, we can execute it, but how. We can transpile this code to Caché code, and execute it.
kill set fs = ##Class(%Stream.FileCharacter).%New() set sc=fs.LinkToFile("c:\advent\input\day12.txt") set src($i(src(0))) = "start(c) new (c)" while 'fs.AtEnd { set line = fs.ReadLine() set pos = $i(src(0)) set code = $$transpile(line, pos, "start") set src(pos) = code } set src($i(src(0))) = " zwrite a" set src($i(src(0))) = " quit" set sc = $compile(src, 0, errs, , , , "AdventDay12New") do start^AdventDay12New() do start^AdventDay12New(1) quit transpile(line, pos = 0, label) { set result = "" set $lb(cmd, arg1, arg2) = $lfs(line," ") if cmd = "jnz" { if +arg1=arg1 set result = " goto:("_arg1_") "_label_"+"_(pos+arg2-1) else set result = " goto:(+$get("_arg1_")) "_label_"+"_(pos+arg2-1) } elseif $lf($lb("cpy", "inc", "dec"), cmd) { set args = $case(cmd, "cpy": $lb(arg2, arg1), "inc": $lb(arg1, arg1_" + 1"), : $lb(arg1, arg1_" - 1")) set result = " set "_$lts(args, " = ") } quit result }
Spoiler. Task 25 have the same language with one more instruction. and with some little modifications in this code, becomes quite easy to solve that task, too.
- Log in to post comments

