--- symmetry.pl 2007/08/26 10:59:01 4 +++ symmetry.pl 2007/08/26 12:17:00 5 @@ -47,7 +47,9 @@ # path traversed my @directions; -my @found; +my @shapes_found; + +my @shapes_start = ( '0,0' ); #( qw/0,0 1,0 0,3/ ); sub draw { my $o = 0; @@ -67,13 +69,31 @@ $trace[ $pos ] = $board[ $pos ]; } +my ( $tr_x, $tr_y ); + +sub pos_x_y { + my $y = int($pos / ($ll*2)); + my $x = int(($pos % $ll) / 2); + + $tr_x = $x unless defined $tr_x; + $tr_y = $y unless defined $tr_y; + + $tr_x = $x if $x > $tr_x && $y == $tr_y; + $tr_y = $y if $y < $tr_y && $x == $tr_x; + + warn "## pos_x_y $pos -> $x,$y\n"; + + return ($x,$y) if wantarray; + return "$x,$y"; +} + sub move { - warn "move $step $step_name[$step]\n"; $pos += $move_by[ $step ]; trace; $pos += $move_by[ $step ]; trace; push @directions, $step; + warn "move $step $step_name[$step] to ", scalar pos_x_y, "\n"; } sub follow { @@ -98,11 +118,11 @@ $trace[ $turn_pos ] = $old; if ( $board[ $turn_pos ] =~ $ok_path ) { - warn "OK can_turn $try_step $step_name[$try_step] turn_pos = $turn_pos b($board[$turn_pos]) t($trace[$turn_pos])"; + warn "OK can_turn $try_step $step_name[$try_step] turn_pos = $turn_pos b($board[$turn_pos]) t($trace[$turn_pos])\n"; $step = $try_step; return 1; } else { - warn "NOPE can_turn $try_step $step_name[$try_step] turn_pos = $turn_pos b($board[$turn_pos]) t($trace[$turn_pos])"; + warn "NOPE can_turn $try_step $step_name[$try_step] turn_pos = $turn_pos b($board[$turn_pos]) t($trace[$turn_pos])\n"; return 0; } } @@ -150,26 +170,32 @@ warn draw( @trace ); if ( $debug ) { + warn "## tr: $tr_x,$tr_y\n"; print "WAIT> press enter | ",show_directions; my $foo = ; } } - push @found, { x => $x, y => $y, len => $len, directions => show_directions }; + push @shapes_found, { x => $x, y => $y, len => $len, directions => show_directions }; warn ">>> ended at $pos, line length: $len, directions traversed: ",show_directions,"\n"; + + my $tr = "$tr_x,$tr_y"; + if ( ! grep( /\Q$tr\E/, @shapes_start ) && $tr_x < 8 ) { + print "INFO: added top-right $tr\n"; + push @shapes_start, $tr; + } + print "WAIT> press enter"; my $foo = ; return $len; } -my $shapes = '0,0 1,0 0,3'; - -foreach my $start ( split(/\s/,$shapes) ) { +foreach my $start ( @shapes_start ) { my $len = shape( split(/,/,$start) ); warn "## $start has $len elements\n"; } print ">>> RESULTS:\n"; -foreach my $r ( @found ) { +foreach my $r ( @shapes_found ) { printf "%2d,%-2d len: %-4d directions: %s\n", $r->{x}, $r->{y}, $r->{len}, $r->{directions}; }