Anonymous avatar Anonymous committed 50c5c75

Refactored into a common function.

Comments (0)

Files changed (1)

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

 
 # Now let's process the layout string and populate the verdicts table.
 
+sub set_verdicts_for_letter_sets
 {
-    my @major_diagonal_letters;
+    my ($letter_list, $maybe_list) = @_;
 
-    $layout_string =~ m{\A(.)};
+    my %cell_is_maybe =
+        (map {; sprintf("%d,%d", @$maybe_list) => 1; } @$maybe_list);
 
-    push @major_diagonal_letters, $1;
-
-    $layout_string =~ m{(.)\n\z};
-
-    push @major_diagonal_letters, $1;
-
-    foreach my $letter_ascii (@major_diagonal_letters)
+    foreach my $letter_ascii (@$letter_list)
     {
         my $letter = get_letter_numeric($letter_ascii);
-
-        my %cell_is_maybe = (map {; "$_,$_" => 1; } (0 .. 4));
-
         foreach my $y (0 .. 4)
         {
             foreach my $x (0 .. 4)
 }
 
 {
+    my @major_diagonal_letters;
+
+    $layout_string =~ m{\A(.)};
+
+    push @major_diagonal_letters, $1;
+
+    $layout_string =~ m{(.)\n\z};
+
+    push @major_diagonal_letters, $1;
+
+    set_verdicts_for_letter_sets(
+        \@major_diagonal_letters, 
+        [map { [$_,$_] } (0 .. 4)],
+    )
+}
+
+{
     my @minor_diagonal_letters;
 
     $layout_string =~ m/\A${letter_re}*($letter_re)\n/ms;
 
     push @minor_diagonal_letters, substr($1,0,1);
 
-    foreach my $letter_ascii (@minor_diagonal_letters)
-    {
-        my $letter = get_letter_numeric($letter_ascii);
-
-        my %cell_is_maybe = 
-            (map {; sprintf("%d,%d", $_ , 4-$_) => 1; } (0 .. 4))
-            ;
-
-        foreach my $y (0 .. 4)
-        {
-            foreach my $x (0 .. 4)
-            {
-                set_verdict($letter, $x, $y,
-                    ((exists $cell_is_maybe{"$x,$y"})
-                        ? $ABCP_VERDICT_MAYBE
-                        : $ABCP_VERDICT_NO
-                    )
-                );
-            }
-        }
-    }
+    set_verdicts_for_letter_sets(
+        \@minor_diagonal_letters,
+        [map { [$_, 4-$_] } (0 .. 4)]
+    );
 }
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.