Shlomi Fish avatar Shlomi Fish committed d352310

Now #95 is working.

Comments (0)

Files changed (1)

project-euler/95/euler-95-amicable-chains.pl

 N_LOOP:
 for my $n (2 .. 1_000_000)
 {
+    if ($n % 10_000 == 0)
+    {
+        print "Reached $n\n";
+    }
+    # print "Checking $n\n";
     my $chain_len = 1;
     my $m = $n;
 
-    while (($m = next_amicable($n)) != 1)
+    my %found = ($n => 1);
+
+    while (($m = next_amicable($m)) != 1)
     {
         $chain_len++;
-        if ($m > 1_000_000)
+        if (($m > 1_000_000) || ($m < $n))
         {
             next N_LOOP;
         }
             }
             next N_LOOP;
         }
+        elsif ($found{$m})
+        {
+            next N_LOOP;
+        }
     }
+    continue
+    {
+        $found{$m} = 1;
+    }
+   
 }
 
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.