Commits

Shlomi Fish committed 85e7810

More stubs of solutions.

Comments (0)

Files changed (6)

+project-euler/75/euler-75

project-euler/75/75.c

+#include <stdio.h>
+#include <math.h>
+#include <string.h>
+
+#define limit 1500000
+
+char verdicts[limit+1];
+
+int main(int argc, char * argv[])
+{
+    int hypotenuse_lim = (limit / 2);
+
+    memset(verdicts, '\0', sizeof(verdicts));
+
+    for (int hypotenuse_length=5 
+            ;
+         hypotenuse_length < hypotenuse_lim
+            ; 
+         hypotenuse_length++
+         )
+    {
+        if (hypotenuse_length % 1000 == 0)
+        {
+            printf("%d\n", hypotenuse_length);
+        }
+
+        long long hypot_sq = hypotenuse_length;
+
+        hypot_sq *= hypot_sq;
+
+        int side1_lim = (hypotenuse_length / 2);
+
+        for(int side1_len = 1 ; side1_len < side1_lim ; side1_len++)
+        {
+            long long side1_sq = side1_len;
+
+            side1_sq *= side1_sq;
+
+            double side2_len = sqrt(hypot_sq - side1_sq);
+            
+            int side2_len_i = (int)side2_len;
+
+            if (side2_len == side2_len_i)
+            {
+                int sum = side2_len_i + side1_len + hypotenuse_length;
+
+                if (sum <= limit)
+                {
+                    if (verdicts[sum] != 2)
+                    {
+                        verdicts[sum]++;
+                    }
+                }
+            }
+        }
+    }
+
+    int count = 0;
+
+    for (int sum = 12 ; sum < limit ; sum++)
+    {
+        if (verdicts[sum] == 1)
+        {
+            count++;
+        }
+    }
+
+    printf("Count = %d\n", count);
+    return 0;
+}

project-euler/75/75.pl

+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+my $limit = 1_500_000;
+
+my $verdicts = "";
+
+my $hypotenuse_lim = int($limit/2);
+
+for my $hypotenuse_length (5 .. $hypotenuse_lim)
+{
+    print "$hypotenuse_length\n" if (not $hypotenuse_length % 1_000);
+    my $hypot_sq = $hypotenuse_length ** 2;
+    
+    my $side1_lim = int($hypotenuse_length / 2);
+    
+    for my $side1_len (1 .. $side1_lim)
+    {
+        my $side2_len = sqrt($hypot_sq - ($side1_len ** 2));
+
+        if ($side2_len == int($side2_len))
+        {
+            my $sum = int($side2_len+$side1_len+$hypotenuse_length);
+            if ($sum <= $limit)
+            {
+                if (vec($verdicts, $sum, 2) != 2)
+                {
+                    vec($verdicts, $sum, 2)++;
+                }
+            }
+        }
+    }
+}
+
+my $count = 0;
+foreach my $sum (12 .. $limit)
+{
+    if (vec($verdicts, $sum, 2) == 1)
+    {
+        $count++
+    }
+}
+
+print "Count = $count\n";
+

project-euler/75/Makefile

+all: euler-75
+
+euler-75: 75.c
+	gcc -std=gnu99 -O2 -o $@ $< -lm
+
+clean:
+	rm -f euler-75

project-euler/77/77.pl

+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+my @primes = `primes 2 10000`;
+chomp(@primes);
+
+my @c_of_n_and_m;
+
+$c_of_n_and_m[2][2] = 1;
+
+foreach my $n (3 .. 500)
+{
+    foreach my $p (
+}

project-euler/77/thinking.txt

+<<<<<<
+It is possible to write ten as the sum of primes in exactly five different ways:
+
+7 + 3
+5 + 5
+5 + 3 + 2
+3 + 3 + 2 + 2
+2 + 2 + 2 + 2 + 2
+
+What is the first value which can be written as the sum of primes in over five thousand different ways?
+>>>>>
+
+2 + 2 = 4
+2 + 3 = 5
+2 + 5 = 7
+2 + 7 = 9
+
+8 = 
+
+C[10]  = Sums Count of 10 = 
+    C[2] * C[8] + C[3] * (C[7] - C[2]) + (
+    (C[5] - C[2]) * (C[5] - C[2])
+
+2
+2 + 2
+2 + 2 + 2
+2 + 2 + 2 + 2
+2 + 2 + 2 + 2 + 2
+
+3
+3 + 3
+3 + 3 + 3
+
+C_Space_[2 x 3] (n) = (n divides by 2) + (n divides by 3) + (n % (2+3))
+
+
+Dynamic programming:
+
+C[2] = 1 (2)
+C[3] = 1 (3)
+C[4] = C[2+2] = 1 * C[2] = 1 (2+2)
+C[5] = 2 (2+3, 5)
+C[6] = (5 x C[1]M[1]) + (3 x C[3]M[3]) + (2 x