学习一点T-sql,并认为一个有趣的练习就是用它生成一个Mandelbrot集.
原来已经有人(最近出现了).我会让其他人发布它作为答案,但我很好奇可以做出哪些优化.
或者,您将如何使代码更具可读性?
我将选择最可读(但相当紧凑)的版本作为已接受的答案(太糟糕了,我们还没有代表奖励!)除非有人真的带来了很好的优化.
奖金指向那些教我一些关于T-sql的答案.
-亚当
解决方法
Create PROCEDURE dbo.mandlebrot @left float,@right float,@Top float,@Bottom float,@Res float,@MaxIterations Integer = 500 As Set NoCount On Declare @Grid Table ( X float Not Null,Y float Not Null,InSet Bit Primary Key (X,Y)) Declare @Xo float,@Yo float,@Abs float Declare @PtX Float,@PtY Float Declare @Iteration Integer Set @Iteration = 0 Select @Xo = @Left,@Yo = @Bottom While @Yo <= @Top Begin While @Xo <= @Right Begin Select @PtX = @Xo,@PtY = @Yo While @Iteration < @MaxIterations And (Square(@PtX) + Square(@PtY)) < 4.0 Begin Select @PtX = Square(@PtX) - Square(@PtY) + @Xo,@PtY = 2* @PtX * @PtY + @Yo Select @Iteration,@PtX,@PtY Set @Iteration = @Iteration + 1 End Insert @Grid(X,Y,InSet) Values(@Xo,@Yo,Case When @Iteration < @MaxIterations Then 1 Else 0 End) Set @Xo = @Xo + @res Set @Iteration = 0 End Select @Xo = @Left,@Yo = @Yo + @Res End Select * From @Grid