Last active
August 29, 2015 14:00
-
-
Save jmervine/b5d985398b3ca7ba16aa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <math.h> | |
int sqr(int x) { | |
return x * x; | |
} | |
int p_find_trip(int final_sum) { | |
int iterations = 0; | |
int stop = ((final_sum / 2) + 1); | |
for (int a = 0; a < stop; a++) { | |
int aSquare = sqr(a); | |
for (int b = a; b < stop; b++) { | |
iterations++; | |
int bSquare = sqr(b); | |
double cDbl = sqrt(double(aSquare) + double(bSquare)); | |
int c = int(cDbl); | |
double cCheck = double(c); | |
if (cDbl == cCheck && (a + b + c) == final_sum) { | |
int abcMul = (a * b * c); | |
std::cout << a << " " << b << " " << c << " " << (a * b * c) << "\n"; | |
std::cout << b << " " << a << " " << c << " " << (a * b * c) << "\n"; | |
} | |
} | |
} | |
std::cout << "iterations: " << iterations << "\n"; | |
return 0; | |
} | |
int main() { | |
return p_find_trip(1000); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math" | |
) | |
func pTripFind(final_sum int) { | |
iterations := 0 | |
stop := (final_sum / 2)+1 | |
for a := 0; a < stop; a++ { | |
aSquare := a * a | |
for b := a; b < stop; b++ { | |
iterations++; | |
bSquare := b * b | |
cflt := math.Sqrt(float64(aSquare + bSquare)) | |
c := int(cflt) | |
cchk := float64(c) | |
if cflt == cchk && (a+b+c) == final_sum { | |
abcMul := a * b * c | |
fmt.Println(a, b, c, abcMul) | |
fmt.Println(b, a, c, abcMul) | |
} | |
} | |
} | |
fmt.Printf("iterations: %d", iterations) | |
} | |
func main() { | |
pTripFind(1000) | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var square = function (x){ | |
return x*x; | |
}; | |
function pTripFind(finalSum){ | |
var iterations = 0; | |
var stop = (finalSum/2)+1; | |
var a, b, c, aSquare, bSquare; | |
for (a=0; a<stop; a++){ | |
aSquare = square(a); | |
for (b=0; b<stop; b++){ | |
iterations++; | |
bSquare = square(b); | |
c = Math.sqrt(aSquare + bSquare); | |
if (c === Math.round(c) && (a + b + c) == finalSum) { | |
console.log (a,b,c,a*b*c); | |
} | |
} | |
} | |
console.log("iterations:", iterations); | |
} | |
pTripFind(1000); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def square(x): | |
return (x * x) | |
def p_trip_find(final_sum): | |
iterations = 0 | |
stop = ((final_sum / 2) + 1) | |
for a in xrange(stop): | |
aSquare = square(a) | |
for b in range(a, stop): | |
iterations = iterations + 1 | |
bSquare = square(b) | |
c = math.sqrt(aSquare + bSquare) | |
if (c == round(c) and (a + b + c) == final_sum): | |
print "{} {} {} {}".format(a, b, c, (a * b * c)) | |
print "{} {} {} {}".format(b, a, c, (a * b * c)) | |
print "iterations: {}".format(iterations) | |
p_trip_find(1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment