#!/usr/bin/perl $cols = 5; @im = []; @pl = []; $min = 0; $min_pos = 0; $decal = 0; sub exec_instr { my $instr = shift(@_); push @instrs, $instr; $tmp = $im[$instr]; $im[$instr] = $im[$instr+1]; $im[$instr+1] = $tmp; $tmp = $pl[$instr]; $pl[$instr] = $pl[$instr+1]; $pl[$instr+1] = $tmp - 1; } sub exec_instr2 { my $instr = shift(@_); my $i = shift(@_); push @{$instrs[$i]}, $instr; $instr += $i; $tmp = $im[$instr]; $im[$instr] = $im[$instr+1]; $im[$instr+1] = $tmp; $tmp = $pl[$instr]; $pl[$instr] = $pl[$instr+1]; $pl[$instr+1] = $tmp - 1; } sub exec_move { my $i = shift(@_); my $to = shift(@_); my @instrs = shift(@_); exec_instr (--$i) while ($i > $to); exec_instr ($i++) while ($i < $to); } sub print_stats { my @print; my $lines = ($#im+1)/$cols; for (my $i = 0; $i < $lines; $i++) { $print[$i] = ""; } for (my $i = 0; $i <= $#im; $i++) { my $j = $i % $lines; if ($i % 3 == 0) { $print[$j] .= "---"; } elsif ($i % 3 == 1 && (($pl[$i] + $pl[$i-1] + $pl[$i+1]) % 2 == 1)) { $print[$j] .= "XXX"; } else { $print[$j] .= " "; } $print[$j] .= sprintf " %3d %3d", $im[$i], $pl[$i]; $print[$j] .= (($i >= $lines * ($cols-1))?"\n":" | "); } print $_ foreach (@print); print "\n--------------------\n"; } sub get_min { for (my $i = 0; $i <= $#im; $i++) { $min_pos = $i if ($im[$i] == $min); } } while(<> =~ /(\d+) -> \((\d+),(\d+)\)/) { $im[$1] = $2; $pl[$1] = $3; } get_min; print("-------\n"); for (my $i = 0; $i <= $#im; $i++) { exec_move $min_pos,$min; $min++; get_min; } for (my $i = $#im; $i > $#im - (($#im+1) % 3); $i--) { $p = $pl[$i]; for (my $j = 1; $j <= $p; $j++) { exec_instr $i-$j; } for (my $j = $p; $j >= 1; $j--) { exec_instr $i-$j; } $decal++; } for (my $i = 0; $i < $#im-1; $i+=3) { if (($pl[$i] + $pl[$i+1] + $pl[$i+2]) % 2 == 1) { exec_instr $i+2; exec_instr $i+2; } } open RES, '>', "black.res"; print RES "bbarker\nplinko\nverify\n"; print RES '|'x$_."><".'|'x($#im-$_-1)."\n" foreach (@instrs); @instrs = []; for (my $i = 0; $i < $#im-1; $i+=3) { push @instrs, []; while ($pl[$i] > $pl[$i+1]) { exec_instr2 0,$i; exec_instr2 1,$i; exec_instr2 1,$i; exec_instr2 0,$i; } while ($pl[$i] < $pl[$i+1]) { exec_instr2 1,$i; exec_instr2 1,$i; } while ($pl[$i+2] > 0) { exec_instr2 1,$i; exec_instr2 0,$i; exec_instr2 0,$i; exec_instr2 1,$i; } while ($pl[$i] > 0) { exec_instr2 0,$i; exec_instr2 0,$i; } } print_stats; $len = 0; for (my $i = 0; $i < $#im-1; $i+=3) { $len = $#{$instrs[$i]} if $#{$instrs[$i]} > $len; } for (my $i = 0; $i <= $len; $i++) { for (my $j = 0; $j < $#im-1; $j+=3) { if ($i <= $#{$instrs[$j]}) { print RES "><|" if ($instrs[$j][$i] == 0); print RES "|><" if ($instrs[$j][$i] == 1); } else { print RES "|||"; } } print RES "|"x$decal; print RES "\n"; } print RES "\n\n\n"; close RES;