#!/usr/bin/perl -w

use strict;

my @code = map { [ split /\s+/ ] } <>;

my $acc = 0;
my $pc = 0;
my %seen;

while (!$seen{$pc}) {
	$seen{$pc} = 1;
	my ($ins, $arg) = @{ $code[$pc] };
	print "pc=$pc, acc=$acc, $ins $arg\n";
	if ($ins eq 'nop') {
		$pc++;
	} elsif ($ins eq 'acc') {
		$acc += $arg; $pc++;
	} elsif ($ins eq 'jmp') {
		$pc += $arg;
	}
}
print "loop at $pc, acc=$acc\n";
