/[symmetry-circle]/symmetry.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /symmetry.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3 by dpavlin, Sun Aug 26 10:26:13 2007 UTC revision 4 by dpavlin, Sun Aug 26 10:59:01 2007 UTC
# Line 26  my $board = << '_BOARD_'; Line 26  my $board = << '_BOARD_';
26  +-+-+-+-+-+-+-+-+  +-+-+-+-+-+-+-+-+
27  _BOARD_  _BOARD_
28    
29    my $debug = shift @ARGV || 0;
30    
31  my @board = map { split(//) } split(/\n/, $board);  my @board = map { split(//) } split(/\n/, $board);
32  my @trace;  my @trace;
33    
# Line 42  my $pos = 0; Line 44  my $pos = 0;
44  # unknown trace position  # unknown trace position
45  my $unknown = ' ';  my $unknown = ' ';
46    
47    # path traversed
48    my @directions;
49    
50    my @found;
51    
52  sub draw {  sub draw {
53          my $o = 0;          my $o = 0;
54          my $out;          my $out;
# Line 66  sub move { Line 73  sub move {
73          trace;          trace;
74          $pos += $move_by[ $step ];          $pos += $move_by[ $step ];
75          trace;          trace;
76          warn draw( @trace );          push @directions, $step;
77  }  }
78    
79  sub follow {  sub follow {
# Line 100  sub can_turn { Line 107  sub can_turn {
107          }          }
108  }  }
109    
110    sub show_directions {
111            return
112                    join('',
113                            map {
114                                    substr($step_name[$_],0,1)
115                            } @directions
116                    )
117            ;
118    }
119    
120  sub shape {  sub shape {
121    
122          my ($x,$y) = @_;          my ($x,$y) = @_;
# Line 108  sub shape { Line 125  sub shape {
125    
126          warn "<<< shape from $x,$y pos: $pos\n";          warn "<<< shape from $x,$y pos: $pos\n";
127          @trace = ($unknown) x ( $#board + 1 );          @trace = ($unknown) x ( $#board + 1 );
128            @directions = ();
129          trace;          trace;
130    
131          my $len = 0;          my $len = 0;
# Line 115  sub shape { Line 133  sub shape {
133          while( 1 ) {          while( 1 ) {
134    
135                  my $next_pos = $pos + $move_by[ $step ];                  my $next_pos = $pos + $move_by[ $step ];
136                  warn "in loop - pos = $pos next_pos = $next_pos step = $step $step_name[$step]\n";                  warn "# pos: $pos next_pos: $next_pos step: $step $step_name[$step] trace: ",show_directions,"\n";
137    
138                  if ( $trace[ $next_pos ] ne $unknown ) {                  if ( $trace[ $next_pos ] ne $unknown ) {
139                          warn "position $next_pos re-visited, exiting\n";                          warn "position $next_pos re-visited, exiting\n";
# Line 131  sub shape { Line 149  sub shape {
149                  }                  }
150                  warn draw( @trace );                  warn draw( @trace );
151    
152                  print "WAIT> press enter"; my $foo = <STDIN>;                  if ( $debug ) {
153                            print "WAIT> press enter | ",show_directions; my $foo = <STDIN>;
154                    }
155          }          }
156    
157          warn ">>> ended at $pos, line length: $len\n";          push @found, { x => $x, y => $y, len => $len, directions => show_directions };
158    
159            warn ">>> ended at $pos, line length: $len, directions traversed: ",show_directions,"\n";
160            print "WAIT> press enter"; my $foo = <STDIN>;
161    
162          return $len;          return $len;
163  }  }
164    
165  my $shapes = '0,0 1,0';  my $shapes = '0,0 1,0 0,3';
166    
167  foreach my $start ( split(/\s/,$shapes) ) {  foreach my $start ( split(/\s/,$shapes) ) {
168          my $len = shape( split(/,/,$start) );          my $len = shape( split(/,/,$start) );
169          warn "## $start has $len elements\n";          warn "## $start has $len elements\n";
170  }  }
171    
172    print ">>> RESULTS:\n";
173    foreach my $r ( @found ) {
174            printf "%2d,%-2d len: %-4d directions: %s\n", $r->{x}, $r->{y}, $r->{len}, $r->{directions};
175    }

Legend:
Removed from v.3  
changed lines
  Added in v.4

  ViewVC Help
Powered by ViewVC 1.1.26