Restructuring
This commit is contained in:
		
							
								
								
									
										18
									
								
								solutions/ProjectEuler/039/desc.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								solutions/ProjectEuler/039/desc.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
			
		||||
title: Integer right triangles
 | 
			
		||||
url: http://projecteuler.net/problem=39
 | 
			
		||||
 | 
			
		||||
desc: |
 | 
			
		||||
    If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120.
 | 
			
		||||
    {20,48,52}, {24,45,51}, {30,40,50}
 | 
			
		||||
    For which value of p <=1000, is the number of solutions maximised?
 | 
			
		||||
      
 | 
			
		||||
solution: |
 | 
			
		||||
  Bruteforce
 | 
			
		||||
 | 
			
		||||
solutions:
 | 
			
		||||
  solve.php:
 | 
			
		||||
    desc: Basic solution
 | 
			
		||||
    language: php
 | 
			
		||||
  solve.c:
 | 
			
		||||
    desc: Basic solution
 | 
			
		||||
    language: c
 | 
			
		||||
							
								
								
									
										28
									
								
								solutions/ProjectEuler/039/solve.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								solutions/ProjectEuler/039/solve.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#define P_VALUE 1000
 | 
			
		||||
 | 
			
		||||
int p, a, b, c, max, key, result = 0;
 | 
			
		||||
int main( )
 | 
			
		||||
{
 | 
			
		||||
	for(p=2;p<P_VALUE;p++)
 | 
			
		||||
	{
 | 
			
		||||
 | 
			
		||||
		for(a=2;a<p;a++)
 | 
			
		||||
		{
 | 
			
		||||
			for(b=a;b<p;b++)
 | 
			
		||||
			{
 | 
			
		||||
				//Find C so it runs faster...
 | 
			
		||||
				c = p - a - b;
 | 
			
		||||
					if(a*a+b*b == c*c) {
 | 
			
		||||
						result++;
 | 
			
		||||
					}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		if(result > max) {
 | 
			
		||||
			max = result;
 | 
			
		||||
			key = p;
 | 
			
		||||
		}
 | 
			
		||||
		result = 0;
 | 
			
		||||
	}
 | 
			
		||||
	printf( "%i", key);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										20
									
								
								solutions/ProjectEuler/039/solve.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								solutions/ProjectEuler/039/solve.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
			
		||||
<?php
 | 
			
		||||
define('P_VALUE',1000);
 | 
			
		||||
 | 
			
		||||
for($p=2;$p<P_VALUE;$p++) {
 | 
			
		||||
 | 
			
		||||
	for($a=2;$a<$p;$a++) {
 | 
			
		||||
		for($b=$a;$b<$p;$b++) {
 | 
			
		||||
			//Find C so it runs faster...
 | 
			
		||||
			$c = $p - $a - $b;
 | 
			
		||||
			if($a*$a+$b*$b == $c*$c) {
 | 
			
		||||
				$result++;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if($result > $max) {
 | 
			
		||||
		$max = $result; $key = $p;
 | 
			
		||||
	}
 | 
			
		||||
	$result = 0;
 | 
			
		||||
}
 | 
			
		||||
echo $key;
 | 
			
		||||
		Reference in New Issue
	
	Block a user