Restructuring

This commit is contained in:
2024-07-01 13:49:44 +00:00
parent f11b705ef0
commit 8d60e1b905
194 changed files with 1296 additions and 112 deletions

View File

@ -0,0 +1,23 @@
title: Find the only Pythagorean triplet, {a, b, c}, for which a + b + c = 1000.
url: http://projecteuler.net/problem=9
desc: |
A Pythagorean triplet is a set of three natural numbers, a b c, for which,
a^2 + b^2 = c^2
For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product abc.
solution: |
Make a nested forloop for a and b in the range 1-1000 - Then c = 1000-a-b - Test if solution is valid.
solutions:
solve.php:
desc: Basic solution
language: php
solve.rb:
desc: Basic solution
language: ruby
solve.c:
desc: ANSI C solution compiled with TCC
language: c

View File

@ -0,0 +1,24 @@
#include "stdio.h"
#include "math.h"
int main( )
{
int a;
int b;
int c;
int cmp;
for(a = 1; a < 1000; a++)
{
for(b = 1; b < 1000; b++)
{
//Calculate the only valid value for c
c = 1000 - a - b;
if( pow(c,2) == (pow(a, 2 ) + pow( b, 2 )))
{
int result = a * b * c;
printf("%i", result);
return 0;
}
}
}
}

View File

@ -0,0 +1,11 @@
<?php
for ($a = 1; $a < 1000; $a++) {
for ($b = 1; $b < 1000; $b++) {
//Make it run reverse in order to find solution quickly
$c = 1000 - $a - $b;
if (pow($a, 2) + pow($b, 2) == pow($c, 2)) {
echo $a * $b * $c;
die;
}
}
}

View File

@ -0,0 +1,9 @@
(1..1000).each do |a|
(1..1000).each do |b|
c = 1000 - a - b
if( a ** 2 + b ** 2 == c ** 2)
puts a * b *c
exit
end
end
end