1. Shlomi Fish
  2. project-euler

Commits

Shlomi Fish  committed d8396b6

Euler #119 - solution takes too long.

I need to think of a better way.

  • Participants
  • Parent commits 3f9235d
  • Branches default

Comments (0)

Files changed (1)

File project-euler/119/euler-119.pl

View file
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use integer;
+
+use List::Util qw(sum);
+
+my $power_num_idx = 0;
+
+for (my $i = 10; ; $i++)
+{
+    my $s = sum(split//,$i);
+
+    if ($s == 1)
+    {
+        next;
+    }
+    my $pow = $s * $s;
+
+    while ($pow < $i)
+    {
+        $pow *= $s;
+    }
+
+    if ($pow == $i)
+    {
+        $power_num_idx++;
+        print "a[$power_num_idx] = $i\n";
+    }
+}
+