#!/usr/bin/perl -w

use strict;
use v5.30;

my %regs;
my @code = map { chomp; $_ } <>;

my $ip = 0;
while ($ip < @code) {
	say "$ip $code[$ip] ", join(', ', map { "$_=$regs{$_}" } sort keys %regs);
	$_ = $code[$ip++];
	if (/cpy (-?\w+) (\w+)/) {
		my $val = $1;
		my $reg = $2;
		$val = $regs{$val} if $val =~ /[a-z]/;
		$regs{$reg} = $val;
	} elsif (/inc (\w+)/) {
		$regs{$1}++;
	} elsif (/dec (\w+)/) {
		$regs{$1}--;
	} elsif (/jnz (-?\w+) (-?\d+)/) {
		my ($reg, $val) = ($1, $2);
		$reg = $regs{$reg} if $reg =~ /[a-z]/;
		if ($reg) {
			$ip += $val - 1;
		}
	} else {
		say "Unknown instrution: $_";
	}
}

say $ip;
say $regs{a};

