Shlomi Fish avatar Shlomi Fish committed 5967a51

Working now.

Comments (0)

Files changed (1)

project-euler/128/euler-128.pl

 
 my $ring_len = 6;
 my $ring_start = 2;
-my ($prev_ring_len, $prev_ring_start);
+my $prev_ring_len = 0;
+my $prev_ring_start = 1;
 my $next_ring_len = 12;
 my $next_ring_start = 8;
 
                     push @vicinity, $x, $x+1;
                 }
             }
-            print "$n ; Neighbours = ", 
-                join(",", sort { $a <=> $b } @vicinity), 
-                "\n";
+            else
+            {
+                {
+                    my $x = $n + 1;
+                    if ($x < $next_ring_start)
+                    {
+                        push @vicinity, $x;
+                    }
+                    else
+                    {
+                        push @vicinity, $ring_start;
+                    }
+                }
+                if ($side == 0)
+                {
+                    # Up and down.
+                    push @vicinity, ($prev_ring_start, $next_ring_start);
+                    push @vicinity, ($next_ring_start-1);
+                    push @vicinity, ($next_ring_start+1);
+                    push @vicinity, ($next_ring_start+$next_ring_len-1);
+                }
+                else
+                {
+                    push @vicinity, $n-1;
+                    push @vicinity, ($prev_ring_start + ($ring-1) * $side);
+                    my $x = $next_ring_start + ($ring+1) * $side;
+                    push @vicinity, ($x-1 .. $x+1);
+                }
+            }
+            # print "$n ; Neighbours = ", 
+            #    join(",", sort { $a <=> $b } @vicinity), 
+            #    "\n";
+        }
+        continue
+        {
             $n++;
         }
     }
 }
 continue
 {
+    
     if ($n != $next_ring_start)
     {
         die "Mismatched $n <=> $next_ring_start";
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.