# Commits

committed a641704

# project-euler/75/75-analysis.txt

`  1   1         0 |  0`
` -------------------------`
` `
`+------------------------------------------`
`+`
`+If A^2 + B^2 = C^2 then so will (mA)^2 + (mB)^2 = (mC)^2`
`+`
`+------------------------------------------`
`+`
`+A^2 + B^2 = C^2 ; A+B+C <= 1,500,000`

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

`+#!/usr/bin/perl`
`+`
`+use strict;`
`+use warnings;`
`+`
`+=head1 DESCRIPTION`
`+`
`+It turns out that 12 cm is the smallest length of wire that can be bent to form an integer sided right angle triangle in exactly one way, but there are many more examples.`
`+`
`+12 cm: (3,4,5)`
`+24 cm: (6,8,10)`
`+30 cm: (5,12,13)`
`+36 cm: (9,12,15)`
`+40 cm: (8,15,17)`
`+48 cm: (12,16,20)`
`+`
`+In contrast, some lengths of wire, like 20 cm, cannot be bent to form an integer sided right angle triangle, and other lengths allow more than one solution to be found; for example, using 120 cm it is possible to form exactly three different integer sided right angle triangles.`
`+`
`+120 cm: (30,40,50), (20,48,52), (24,45,51)`
`+`
`+Given that L is the length of the wire, for how many values of L ≤ 1,500,000 can exactly one integer sided right angle triangle be formed?`
`+`
`+Note: This problem has been changed recently, please check that you are using the right parameters.`
`+`
`+=cut`
`+`
`+sub gcd`
`+{`
`+    my (\$n, \$m) = @_;`
`+`
`+    if (\$m == 0)`
`+    {`
`+        return \$n;`
`+    }`
`+`
`+    return gcd(\$m,\$n % \$m);`
`+}`
`+`
`+my \$limit = 1_500_000;`
`+`
`+my \$verdicts = "";`
`+`
`+my \$hypotenuse_lim = int(\$limit/2);`
`+`
`+my \$major_side_limit = int(\$limit/2);`
`+`
`+MAJOR_SIDE:`
`+for my \$major_side (4 .. \$major_side_limit)`
`+{`
`+    if (\$major_side % 100 == 0)`
`+    {`
`+        print "Maj=\$major_side\n";`
`+    }`
`+    MINOR_SIDE:`
`+    for my \$minor_side (3 .. (\$major_side - 1))`
`+    {`
`+        if (gcd( \$major_side , \$minor_side ) != 1)`
`+        {`
`+            next MINOR_SIDE;`
`+        }`
`+`
`+        my \$hypot_sq = \$major_side * \$major_side + \$minor_side * \$minor_side;`
`+`
`+        my \$hypot = sqrt(\$hypot_sq);`
`+        if (\$hypot == int(\$hypot))`
`+        {`
`+            my \$sum = \$major_side + \$minor_side + \$hypot;`
`+            `
`+            if (\$sum > \$limit)`
`+            {`
`+                last MINOR_SIDE;`
`+            }`
`+`
`+            my \$sum_product = \$sum;`
`+`
`+            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)`
`+                {`
`+                    vec(\$verdicts, \$idx, 2)++;`
`+                }`
`+                \$sum_product += \$sum;`
`+            }`
`+        }`
`+    }`
`+}`
`+`
`+my \$count = 0;`
`+foreach my \$sum_idx ((12>>1) .. (\$limit>>1))`
`+{`
`+    if (vec(\$verdicts, \$sum_idx, 2) == 1)`
`+    {`
`+        \$count++`
`+    }`
`+}`
`+`
`+print "Count = \$count\n";`
`+`

# project-euler/75/75.pl

` use strict;`
` use warnings;`
` `
`+=head1 DESCRIPTION`
`+`
`+It turns out that 12 cm is the smallest length of wire that can be bent to form an integer sided right angle triangle in exactly one way, but there are many more examples.`
`+`
`+12 cm: (3,4,5)`
`+24 cm: (6,8,10)`
`+30 cm: (5,12,13)`
`+36 cm: (9,12,15)`
`+40 cm: (8,15,17)`
`+48 cm: (12,16,20)`
`+`
`+In contrast, some lengths of wire, like 20 cm, cannot be bent to form an integer sided right angle triangle, and other lengths allow more than one solution to be found; for example, using 120 cm it is possible to form exactly three different integer sided right angle triangles.`
`+`
`+120 cm: (30,40,50), (20,48,52), (24,45,51)`
`+`
`+Given that L is the length of the wire, for how many values of L ≤ 1,500,000 can exactly one integer sided right angle triangle be formed?`
`+`
`+Note: This problem has been changed recently, please check that you are using the right parameters.`
`+`
`+=cut`
`+`
` my \$limit = 1_500_000;`
` `
` my \$verdicts = "";`
` HYPO:`
` for my \$hypotenuse_length (5 .. \$hypotenuse_lim)`
` {`
`-    if (\$hypotenuse_length & 0x1)`
`-    {`
`-        `
`-    }`
`-`
`     print "\$hypotenuse_length\n" if (not \$hypotenuse_length % 1_000);`
`     my \$hypot_sq = \$hypotenuse_length ** 2;`
`     `
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.