part2, start

This commit is contained in:
Yanick Champoux 2017-12-23 15:09:19 -05:00
parent 86b2028152
commit a46831ff0d
2 changed files with 43 additions and 33 deletions

11
23/2.pl
View File

@ -1,5 +1,6 @@
use 5.20.0;
my $script = "\$a = 1;\n";
while(<>) {
s/\b[a-h]\b/\$$&/g;
s/sub (\S+) (\S+)/$1 -= $2;/;
@ -7,9 +8,17 @@ while(<>) {
s/mul (\S+) (\S+)/$1 *= $2;/;
s/jnz (\S+) (\S+)/"goto L" . ($. + $2) . " if $1;"/e;
s/^/L${.}: /;
print;
$script .= $_;
}
for ( 1..35 ) {
my @c = $script =~ /(L$_: )/g;
next if @c > 1;
$script =~ s/L$_: //g;
}
print $script;
__END__
my $i = 0;

View File

@ -1,32 +1,33 @@
L1: $b = 79;
L2: $c = $b;
L3: goto L5 if $a;
L4: goto L9 if 1;
L5: $b *= 100;
L6: $b -= -100000;
L7: $c = $b;
L8: $c -= -17000;
L9: $f = 1;
L10: $d = 2;
L11: $e = 2;
L12: $g = $d;
L13: $g *= $e;
L14: $g -= $b;
L15: goto L17 if $g;
L16: $f = 0;
L17: $e -= -1;
L18: $g = $e;
L19: $g -= $b;
L20: goto L12 if $g;
L21: $d -= -1;
L22: $g = $d;
L23: $g -= $b;
L24: goto L11 if $g;
L25: goto L27 if $f;
L26: $h -= -1;
L27: $g = $b;
L28: $g -= $c;
L29: goto L31 if $g;
L30: goto L33 if 1;
L31: $b -= -17;
L32: goto L9 if 1;
$a = 1;
$b = 79;
$c = $b;
goto L5 if $a;
goto L9 if 1;
$b *= 100;
$b -= -100000;
$c = $b;
$c -= -17000;
$f = 1;
$d = 2;
$e = 2;
$g = $d;
$g *= $e;
$g -= $b;
goto L17 if $g;
$f = 0;
$e -= -1;
$g = $e;
$g -= $b;
goto L12 if $g;
$d -= -1;
$g = $d;
$g -= $b;
goto L11 if $g;
goto L27 if $f;
$h -= -1;
$g = $b;
$g -= $c;
goto L31 if $g;
goto L33 if 1;
$b -= -17;
goto L9 if 1;