diff --git a/23/2.pl b/23/2.pl index df13281..d6fa3a1 100644 --- a/23/2.pl +++ b/23/2.pl @@ -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; diff --git a/23/2b.pl b/23/2b.pl index 582955c..ff1bc19 100644 --- a/23/2b.pl +++ b/23/2b.pl @@ -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;