Post date: May 21, 2014 10:43:28 AM
Finally finishing up the first 10.
"There exists one set of numbers such that a**2 + b**2 = c**2, a + b + c = 1000, < b < c, and all numbers are greater than 1. Find a, b, and c." Ok, and because Project Euler only has a single form field for the answer, multiply them together. But that's just being lazy, so don't get too worked up about it.
CREATE TABLE #Integers (i INT NOT NULL PRIMARY KEY)
; WITH Ten(i) AS
(
SELECT 0
UNION ALL
SELECT i + 1
FROM Ten
WHERE i < 9
),
Integers(i) AS
(
SELECT 100 * h.i + 10 * t.i + o.i + 1
FROM Ten o
CROSS JOIN Ten t
CROSS JOIN Ten h
)
INSERT INTO #Integers
SELECT i
FROM Integers
SELECT i1.i, i2.i, i3.i, i1.i * i2.i * i3.i
FROM #Integers i1
CROSS JOIN #Integers i2
CROSS JOIN #Integers i3
WHERE i1.i + i2.i + i3.i = 1000
AND POWER(i1.i,2) + POWER(i2.i,2) = POWER(i3.i,2)
AND i3.i > i2.i
AND i2.i > i1.i
DROP TABLE #Integers