×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: SQL
Posted by: Jon Nickerson
Added: Apr 16, 2018 1:53 PM
Views: 5
Tags: no tags
  1. WITH RECURSIVE
  2. x(i)
  3. AS (
  4.     VALUES(0)
  5. UNION ALL
  6.     SELECT i + 1 FROM x WHERE i < 101
  7. ),
  8. Z(Ix, Iy, Cx, Cy, X, Y, I)
  9. AS (
  10.     SELECT Ix, Iy, X::FLOAT, Y::FLOAT, X::FLOAT, Y::FLOAT, 0
  11.     FROM
  12.         (SELECT -2.2 + 0.031 * i, i FROM x) AS xgen(x,ix)
  13.     CROSS JOIN
  14.         (SELECT -1.5 + 0.031 * i, i FROM x) AS ygen(y,iy)
  15.     UNION ALL
  16.     SELECT Ix, Iy, Cx, Cy, X * X - Y * Y + Cx AS X, Y * X * 2 + Cy, I + 1
  17.     FROM Z
  18.     WHERE X * X + Y * Y < 16.0
  19.     AND I < 27
  20. ),
  21. Zt (Ix, Iy, I) AS (
  22.     SELECT Ix, Iy, MAX(I) AS I
  23.     FROM Z
  24.     GROUP BY Iy, Ix
  25.     ORDER BY Iy, Ix
  26. )
  27. SELECT array_to_string(
  28.     array_agg(
  29.         SUBSTRING(
  30.             ' .,,,-----++++%%%%@@@@#### ',
  31.             GREATEST(I,1),
  32.             1
  33.         )
  34.     ),''
  35. )
  36. FROM Zt
  37. GROUP BY Iy
  38. ORDER BY Iy;