Created
September 25, 2010 10:44
-
-
Save marioaquino/596724 to your computer and use it in GitHub Desktop.
This file contains 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
/* Implementation by Jesse Phelps & Tomasz Mozolewski */ | |
DECLARE @maxGen int | |
set @maxgen = (select MAX(generation) from Cells) | |
--insert into cells | |
;WITH cte AS | |
( | |
SELECT -1 x | |
UNION ALL | |
SELECT x + 1 | |
FROM cte | |
WHERE x < 1 | |
) | |
insert into Cells | |
select newGen, g.xcoord, g.ycoord | |
from ( | |
select @maxgen + 1 as newGen, xcoord - coordPairs.x as xcoord, ycoord - coordPairs.y as ycoord | |
from cells, (SELECT cte.x, cte2.x as y | |
FROM cte, cte as cte2 | |
where not (cte.x = 0 and cte2.x = 0) | |
) coordPairs | |
where generation = @maxGen | |
) g left outer join Cells c | |
on c.xcoord = g.xcoord and c.ycoord = g.ycoord and g.newGen -1 = c.generation | |
group by g.xcoord, g.ycoord, newGen, c.xcoord | |
having (COUNT(*) = 3) or (COUNT(*) = 2 and c.xcoord is not null) | |
select generation, xcoord, ycoord from cells | |
--DELETE FROM Cells | |
--where generation > 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment