Anonymous avatar Anonymous committed a2caddf

Refactored the input method.

It now uses @rows globally for everything instead of doing char-fiddling in
the monolithic string.

Comments (0)

Files changed (1)

abc-path/perl-quick-and-dirty/abc-path-solver.pl

     return join(',', @{$solver->get_possible_letters_for_cell($x,$y)});
 }
 
-
 sub neighbourhood_and_individuality_inferring
 {
     my ($solver) = @_;
 
     my $layout_string = $args->{layout};
 
-    my $letter_re = qr{[A-Y]};
-    my $letter_and_space_re = qr{[ A-Y]};
+    my $letter_re_s = join('', map { quotemeta($_) } @letters);
+    my $letter_re = qr{[$letter_re_s]};
+    my $letter_and_space_re = qr{[ $letter_re_s]};
     my $top_bottom_re = qr/^${letter_re}{7}\n/ms;
     my $inner_re = qr/^${letter_re}${letter_and_space_re}{5}${letter_re}\n/ms;
 
         die "Invalid format. Should be Letter{7}\n(Letter{spaces or one letter}{5}Letter){5}\nLetter{7}";
     }
 
+    my @rows = split(/\n/, $layout_string);
+
     {
         my %count_letters = (map { $_ => 0 } @letters);
         foreach my $letter ($layout_string =~ m{($letter_re)}g)
             }
         }
     }
-# Now let's process the layout string and populate the verdicts table.
+    # Now let's process the layout string and populate the verdicts table.
 
     {
         my @major_diagonal_letters;
 
-        $layout_string =~ m{\A(.)};
+        $rows[0] =~ m{\A($letter_re)};
 
         push @major_diagonal_letters, $1;
 
-        $layout_string =~ m{(.)\n\z};
+        $rows[-1] =~ m{($letter_re)\z};
 
         push @major_diagonal_letters, $1;
 
     {
         my @minor_diagonal_letters;
 
-        $layout_string =~ m/\A${letter_re}*($letter_re)\n/ms;
+        $rows[0] =~ m{($letter_re)\z};
 
         push @minor_diagonal_letters, $1;
 
-        $layout_string =~ m{($letter_re*)\n\z}ms;
+        $rows[-1] =~ m{\A($letter_re)};
 
-        push @minor_diagonal_letters, substr($1,0,1);
+        push @minor_diagonal_letters, $1;
 
         $solver->set_verdicts_for_letter_sets(
             \@minor_diagonal_letters,
     }
 
     {
-        my ($top_row) = ($layout_string =~ m/\A(${letter_re}*)\n/ms);
-        my ($bottom_row) = ($layout_string =~ m/(${letter_re}*)\n\z/ms);
+        my $top_row = $rows[0];
+        my $bottom_row = $rows[-1];
 
         foreach my $x (0 .. $BOARD_LEN_LIM)
         {
     }
 
     {
-        my @rows = split(/\n/, $layout_string);
 
         my ($clue_x, $clue_y, $clue_letter);
         foreach my $y (0 .. $BOARD_LEN_LIM)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.