#!/usr/bin/env tclsh while {[gets stdin line] >= 0} { if {$line eq ""} continue lappend memory [split $line { }] } set pc 0 set acc 0 while 1 { if {[info exists visited($pc)]} break set visited($pc) 1 lassign [lindex $memory $pc] op arg switch -- $op { nop {incr pc} acc {incr acc $arg; incr pc} jmp {incr pc $arg} } } puts $acc