Skip to content

Instantly share code, notes, and snippets.

@luca
Forked from rupey/mandelbrot.sql
Last active August 29, 2015 14:25
Show Gist options
  • Save luca/f7aa5e6889ac0bab645c to your computer and use it in GitHub Desktop.
Save luca/f7aa5e6889ac0bab645c to your computer and use it in GitHub Desktop.

Revisions

  1. @rupey rupey renamed this gist Jul 20, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. @rupey rupey revised this gist Jul 20, 2015. 2 changed files with 105 additions and 0 deletions.
    File renamed without changes.
    105 changes: 105 additions & 0 deletions result.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,105 @@
    array_to_string
    --------------------------------------------------------------------------------------------------------
    ....................................................................................
    .......................................................................................
    .........................................................................................
    ...........................................................................................
    ....................................................,,,,,,,,,.................................
    ................................................,,,,,,,,,,,,,,,,,,.............................
    ..............................................,,,,,,,,,,,,,,,,,,,,,,,,..........................
    ............................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,........................
    ..........................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,......................
    .........................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,....................
    ........................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,...................
    .......................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.................
    .......................................,,,,,,,,,,,,,,,,,,,,,,,,--,,,,,,,,,,,,,,,,,,,,................
    ......................................,,,,,,,,,,,,,,,,,,,,,,,,,,-+--,,,,,,,,,,,,,,,,,,,...............
    ....................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,-----,,,,,,,,,,,,,,,,,,,..............
    ...................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,--- -----,,,,,,,,,,,,,,,,,.............
    .................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,---++--++,,,,,,,,,,,,,,,,,,............
    ................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,-----%++---,,,,,,,,,,,,,,,,,............
    ..............................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,-----+%----,,,,,,,,,,,,,,,,,,...........
    .............................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,----- %%+----,,,,,,,,,,,,,,,,,,..........
    ...........................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,---%-+% ----,,,,,,,,,,,,,,,,,,,.........
    ..........................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,---+ +## %+%---,,,,,,,,,,,,,,,,,,.........
    ........................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,-----# # +---,,,,,,,,,,,,,,,,,,........
    .......................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,-------% %-----,,,,,,,,,,,,,,,,,........
    .....................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,---------+ ------,,,,,,,,,,,,,,,,,.......
    ....................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,-----------+@ +-----------,,,,,,,,,,,,.......
    ..................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,----@-------++ ++-----------,,,,,,,,,,,,......
    .................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,--+@% ---+ +@%%@ %%+@+@%------+-,,,,,,,,,,,......
    ................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,---- # ++% % @-----++--,,,,,,,,,,,.....
    ..............,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,----+ % %%++ %+%@-,,,,,,,,,,,.....
    .............,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,-----+# #% ++-,,,,,,,,,,,,....
    ............,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,------+ @---,,,,,,,,,,,,....
    ..........,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,-------++% ---,,,,,,,,,,,,....
    .........,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,--------+ + %+---,,,,,,,,,,,,,...
    ........,,,,,,,,,,,,,,,,,,,,,--------------------@ +----,,,,,,,,,,,,...
    .......,,,,,,,,,,,,,,,,,,,,,,- +-----------------+ ----,,,,,,,,,,,,...
    .......,,,,,,,,,,,,,,,,,,,,,--++------+---------+% +++--,,,,,,,,,,,,..
    ......,,,,,,,,,,,,,,,,,,,,,,--%+-----++--------- #+-,,,,,,,,,,,,..
    .....,,,,,,,,,,,,,,,,,,,,,,----#%++--+@ -+-----+% --,,,,,,,,,,,,..
    .....,,,,,,,,,,,,,,,,,,,,,,-----+## ++@ + +----% +--,,,,,,,,,,,,,..
    ....,,,,,,,,,,,,,,,,,,,,,,------+@ @ @@++++# +--,,,,,,,,,,,,,..
    ....,,,,,,,,,,,,,,,,,,,,,-------% #++% -,,,,,,,,,,,,,..
    ...,,,,,,,,,,,,,,,,,,,,,------++%# %%@ %-,,,,,,,,,,,,,,.
    ...,,,,,,,,,,,,,,,,,,,--------+ % +--,,,,,,,,,,,,,,.
    ...,,,,,,,,,,,,,,,,,,-----+--++@ # --,,,,,,,,,,,,,,.
    ..,,,,,,,,,,,,,,,,,-------%+++% @--,,,,,,,,,,,,,,,.
    ..,,,,,,,,,,,-------------+ @#@ ---,,,,,,,,,,,,,,,.
    ..,,,,,,,,,---@--------@-+% +---,,,,,,,,,,,,,,,.
    ..,,,,,------- +-++++-+%%% +----,,,,,,,,,,,,,,,.
    ..,,,,,,------%--------++% +----,,,,,,,,,,,,,,,.
    ..,,,,,,,,,,--+----------++# ---,,,,,,,,,,,,,,,.
    ..,,,,,,,,,,,,------------+@@@% +--,,,,,,,,,,,,,,,.
    ..,,,,,,,,,,,,,,,,,------- +++% %--,,,,,,,,,,,,,,,.
    ...,,,,,,,,,,,,,,,,,,---------+@ @ --,,,,,,,,,,,,,,.
    ...,,,,,,,,,,,,,,,,,,,,------- # %@ +--,,,,,,,,,,,,,,.
    ...,,,,,,,,,,,,,,,,,,,,,-------++@ %+ %-,,,,,,,,,,,,,,.
    ....,,,,,,,,,,,,,,,,,,,,,------- %++% %-,,,,,,,,,,,,,..
    ....,,,,,,,,,,,,,,,,,,,,,,------+# %# #@ ++++ +--,,,,,,,,,,,,,..
    .....,,,,,,,,,,,,,,,,,,,,,,-----+ %%++% +@+----+ +--,,,,,,,,,,,,,..
    .....,,,,,,,,,,,,,,,,,,,,,,,---%+++--+#+--------% #--,,,,,,,,,,,,..
    ......,,,,,,,,,,,,,,,,,,,,,,--++-----%%--------- @#--,,,,,,,,,,,,..
    .......,,,,,,,,,,,,,,,,,,,,,---------------------+@ +-++,,,,,,,,,,,,...
    ........,,,,,,,,,,,,,,,,,,,,,--------------------+ ----,,,,,,,,,,,,...
    .........,,,,,,,,,,,,,,,,,,,,----,,,------------- #+----,,,,,,,,,,,,...
    ..........,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,-------+ + +---,,,,,,,,,,,,,...
    ...........,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,--------+%# #---,,,,,,,,,,,,....
    ............,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,------+# @ @---,,,,,,,,,,,,....
    .............,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,-----+# + @--,,,,,,,,,,,,....
    ..............,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,---+% %+@ %+-+ +++%-,,,,,,,,,,,.....
    ................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,----% %@++ # % -----++-,,,,,,,,,,,,.....
    .................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,-- ++ ---+ + +%@ %++++++------%-,,,,,,,,,,,......
    ...................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,---- -------++ +------------,,,,,,,,,,,,......
    ....................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,-----------+% +--------,,,,,,,,,,,,,,,.......
    ......................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,--------+# -----,,,,,,,,,,,,,,,,,,.......
    .......................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,-------+ #----,,,,,,,,,,,,,,,,,,........
    .........................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,----+% %#---,,,,,,,,,,,,,,,,,,,........
    ..........................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,---+%+%@ %+%%--,,,,,,,,,,,,,,,,,,.........
    ............................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,---+-+% %----,,,,,,,,,,,,,,,,,,..........
    .............................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,-----+%@+---,,,,,,,,,,,,,,,,,,,..........
    ...............................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,-----+%----,,,,,,,,,,,,,,,,,,...........
    ................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,-----%+ +--,,,,,,,,,,,,,,,,,............
    ..................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,---++----,,,,,,,,,,,,,,,,,.............
    ...................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,---@-----,,,,,,,,,,,,,,,,,.............
    .....................................,,,,,,,,,,,,,,,,,,,,,,,,,,,-----,,,,,,,,,,,,,,,,,,,..............
    .....................................,,,,,,,,,,,,,,,,,,,,,,,,,,--%,,,,,,,,,,,,,,,,,,,,...............
    .......................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.................
    ........................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,..................
    ........................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,...................
    .........................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,....................
    ..........................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,......................
    ............................................,,,,,,,,,,,,,,,,,,,,,,,,,,,,........................
    .............................................,,,,,,,,,,,,,,,,,,,,,,,,..........................
    ................................................,,,,,,,,,,,,,,,,,.............................
    .....................................................,,,,....................................
    ...........................................................................................
    .........................................................................................
    ......................................................................................
    ....................................................................................
    .................................................................................
    ..............................................................................
    ...........................................................................
    ........................................................................
    (102 rows)
  3. @rupey rupey created this gist Jul 20, 2015.
    53 changes: 53 additions & 0 deletions gistfile1.sql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    WITH RECURSIVE
    x(i) AS ( VALUES (0)
    UNION ALL SELECT i + 1
    FROM x
    WHERE i < 101),
    Z(Ix, Iy, Cx, Cy, X, Y, I) AS (
    SELECT
    Ix,
    Iy,
    X :: FLOAT,
    Y :: FLOAT,
    X :: FLOAT,
    Y :: FLOAT,
    0
    FROM
    (SELECT
    -2.2 + 0.031 * i,
    i
    FROM x) AS xgen(x, ix) CROSS JOIN
    (SELECT
    -1.5 + 0.031 * i,
    i
    FROM x) AS ygen(y, iy)
    UNION ALL
    SELECT
    Ix,
    Iy,
    Cx,
    Cy,
    X * X - Y * Y + Cx AS X,
    Y * X * 2 + Cy,
    I + 1
    FROM Z
    WHERE X * X + Y * Y < 16.0
    AND I < 27),
    Zt (Ix, Iy, I) AS (
    SELECT
    Ix,
    Iy,
    MAX(I) AS I
    FROM Z
    GROUP BY Iy, Ix
    ORDER BY Iy, Ix
    )
    SELECT array_to_string(
    array_agg(SUBSTRING(
    ' .,,,-----++++%%%%@@@@#### ', GREATEST(I, 1),
    1
    )), ''
    )
    FROM Zt
    GROUP BY Iy
    ORDER BY Iy;