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

View File

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