119 |
my $ok_path = qr/[\|\-]/; |
my $ok_path = qr/[\|\-]/; |
120 |
|
|
121 |
my @corners; |
my @corners; |
122 |
|
my $corners_usage; |
123 |
|
|
124 |
sub can_turn { |
sub can_turn { |
125 |
my $try_step = shift; |
my $try_step = shift; |
140 |
warn "OK can_turn $try_step $step_name[$try_step] turn_pos = $turn_pos b($board[$turn_pos]) t($trace[$turn_pos]) from $xy\n"; |
warn "OK can_turn $try_step $step_name[$try_step] turn_pos = $turn_pos b($board[$turn_pos]) t($trace[$turn_pos]) from $xy\n"; |
141 |
$step = $try_step; |
$step = $try_step; |
142 |
push @corners, $xy; |
push @corners, $xy; |
143 |
|
$corners_usage->{$xy}++; |
144 |
return 1; |
return 1; |
145 |
} else { |
} else { |
146 |
warn "NOPE can_turn $try_step $step_name[$try_step] turn_pos = $turn_pos b($board[$turn_pos]) t($trace[$turn_pos])\n"; |
warn "NOPE can_turn $try_step $step_name[$try_step] turn_pos = $turn_pos b($board[$turn_pos]) t($trace[$turn_pos])\n"; |
172 |
my $len = 0; |
my $len = 0; |
173 |
$step = 0; |
$step = 0; |
174 |
|
|
175 |
warn "<<< shape from $x,$y pos: $pos\n"; |
my $usage = $corners_usage->{"$x,$y"} || 0; |
176 |
|
|
177 |
|
warn "<<< shape from $x,$y [usage: $usage] pos: $pos\n"; |
178 |
|
|
179 |
|
if ( $usage > 4 ) { |
180 |
|
warn "SKIPPED, usage > 4\n"; |
181 |
|
return; |
182 |
|
} |
183 |
|
|
184 |
while( 1 ) { |
while( 1 ) { |
185 |
|
|
207 |
|
|
208 |
push @shapes_found, { x => $x, y => $y, len => $len, directions => show_directions }; |
push @shapes_found, { x => $x, y => $y, len => $len, directions => show_directions }; |
209 |
|
|
210 |
warn "### corners: ",join(' ', @corners),"\n"; |
warn "### corners: ",join(' ', map { $_ . " [" . $corners_usage->{$_} . "]" } @corners),"\n"; |
211 |
warn ">>> ended at $pos, line length: $len, directions traversed: ",show_directions,"\n"; |
warn ">>> ended at $pos, line length: $len, directions traversed: ",show_directions,"\n"; |
212 |
|
|
213 |
foreach my $c ( @corners ) { |
foreach my $c ( @corners ) { |
232 |
} |
} |
233 |
} |
} |
234 |
|
|
235 |
|
sub is_symmetric { |
236 |
|
my $path = shift || die "no path?"; |
237 |
|
|
238 |
|
my $h = length($path)/2; |
239 |
|
return 0 if int($h) != $h; |
240 |
|
my ($l,$r) = ( substr($path,0,$h), substr($path,$h) ); |
241 |
|
$r =~ tr/lrud/rldu/; |
242 |
|
# warn "$l -- $r\n"; |
243 |
|
return 0 unless $l eq $r; |
244 |
|
return 1; |
245 |
|
} |
246 |
|
|
247 |
print ">>> RESULTS:\n"; |
print ">>> RESULTS:\n"; |
248 |
foreach my $r ( @shapes_found ) { |
foreach my $r ( @shapes_found ) { |
249 |
printf "%2d,%-2d len: %-4d directions: %s\n", $r->{x}, $r->{y}, $r->{len}, $r->{directions}; |
printf "%2d,%-2d len: %-4d directions: %s %s\n", |
250 |
|
$r->{x}, $r->{y}, $r->{len}, $r->{directions}, is_symmetric($r->{directions}) ? 'symetric' : ''; |
251 |
} |
} |