Commits

committed 7615ebd

An optimisation - still not enough.

• Participants
• Parent commits 318d863

File project-euler/75/75-take2.pl

` }`
` `
` my \$limit = 1_500_000;`
`+my \$half_limit = (\$limit >> 1);`
` `
` my \$verdicts = "";`
` `
`         my \$hypot = sqrt(\$hypot_sq);`
`         if (\$hypot == int(\$hypot))`
`         {`
`-            my \$sum = \$major_side + \$minor_side + \$hypot;`
`+            # Only even numbers can be sums, so we can divide the index`
`+            # by 2.`
`+            # See 75-analysis.txt`
`+            my \$sum = ((\$major_side + \$minor_side + \$hypot) >> 1);`
`             `
`-            if (\$sum > \$limit)`
`+            if (\$sum > \$half_limit)`
`             {`
`                 last MINOR_SIDE;`
`             }`
` `
`-            my \$sum_product = \$sum;`
`+            if (vec(\$verdicts, \$sum, 2) != 2)`
`+            {`
`+                my \$sum_product = 0;`
` `
`-            while (\$sum_product < \$limit)`
`-            {`
`-                # Only even numbers can be sums, so we can divide the index`
`-                # by 2.`
`-                # See 75-analysis.txt`
`-                my \$idx = (\$sum_product>>1);`
`-                if (vec(\$verdicts, \$idx, 2) != 2)`
`+                while ((\$sum_product += \$sum) < \$half_limit)`
`                 {`
`-                    vec(\$verdicts, \$idx, 2)++;`
`+                    if (vec(\$verdicts, \$sum_product, 2) != 2)`
`+                    {`
`+                        vec(\$verdicts, \$sum_product, 2)++;`
`+                    }`
`                 }`
`-                \$sum_product += \$sum;`
`             }`
`         }`
`     }`

File project-euler/75/TEST1.pl

`+#!/usr/bin/perl`
`+`
`+use strict;`
`+use warnings;`
`+`
`+my \$s = "";`
`+`
`+vec(\$s,0,2) = 3;`
`+vec(\$s,0,2)++;`
`+`
`+print "Foo = ", vec(\$s,0,2), "\n";`