• Edvardas (unregistered) in reply to g
    g:
    2005+ (as it uses PIVOT).

    It only took 11 seconds to run on my local VM, so I think you'll be alright ;)

    It was fun running it on the live production server, 12 seconds :[D

  • Mr.'; Drop Database -- (unregistered) in reply to Bob
    Bob:
    Actually, why not just use asterisks then ... or even just numbers showing the number of letters.
    Uncyclopedia has an example of that.
  • Rich (unregistered)

    Thats pretty awesome!

  • Bob Fractal (unregistered)

    This has already been done in SQL: http://forge.mysql.com/tools/tool.php?id=25 and the source was more elegant.

  • PaulG (unregistered)

    I feel much better about my lotto number generator I once wrote in SQL.

  • Rhialto (unregistered) in reply to dkf
    dkf:
    This reminds me of when (many years ago now) we sent a postscript file to our brand-new 300dpi printer which computed and displayed the Mandelbrot set at maximum resolution, with all computations performed in the PS interpreter. I don't remember if it was an overnight job or an "over a long weekend" job, but it was definitely awesome...

    No, I don't have the code.

    A friend of mine once coded the solution to the Towes of Hanoi. In Postscript. Fully animated. Too bad he left out all the showpage commands :-) But it looked pretty in Ghostscript.

  • anoncow (unregistered)

    Here's an obfuscated C version of the above. Expects an 80 column output window.

    #define problems > #define crazy ++ #define confused = #define fool < #define obfuscation for #define decoding putchar #define makes ( #define absolutely ) #define no { #define sense float #define bamboozled } #define screw += #define this main #define hell * this makes absolutely no sense totally, bloody, pissed, even_more, you, me; obfuscation makes me confused -15; me fool 16; me crazy absolutely obfuscation makes you confused -63; you fool 17; decoding makes even_more problems 116?32:46 absolutely, you crazy absolutely obfuscation makes totally confused bloody confused even_more confused 0; even_more crazy fool 116&& totally hell totally + bloody hell bloody fool 4; pissed confused totally, totally confused totally hell totally - bloody hell bloody, bloody confused pissed hell bloody hell 2, totally screw you / 40, bloody screw me / 16 absolutely;bamboozled

  • Whitehat (unregistered)

    Sentinel has converted the following code into oracle syntax in the following thread:

    http://forums.oracle.com/forums/thread.jspa?threadID=828677

    hope he doesn't mind me reposting:

    with ord as (select rownum - 1 xyz from dual connect by rownum <= 100) , xgen as ( select -2.2 + xyz0.031 cx, xyz ix from ord) , ygen as ( select -1.5 + xyz0.031 cy, xyz iy from ord) , z as ( select ix, iy, i from xgen, ygen model partition by (ix, iy) dimension by (0 i) measures (cx, cy , cx x , cy y ) ignore nav rules iterate (100) until (X[iteration_number] * X[iteration_number] + Y[iteration_number] * Y[iteration_number] > 16) ( cx[iteration_number] = cx[cv()]+cx[cv()-1] , cy[iteration_number] = cy[cv()]+cy[cv()-1] , x[iteration_number] = cx[cv()]+x[cv()-1]*x[cv()-1]-y[cv()-1]*y[cv()-1] , y[iteration_number] = cy[cv()]+y[cv()-1]*x[cv()-1]*2 ) ) select replace(ltrim(max(sys_connect_by_path(i,'|')) keep (dense_rank last partition by ix),'|'),'|') from (select ix, iy, substr(' .,,,-----++++%%%%@@@@### ',least(max(i),26),1) i from z group by ix, iy) connect by iy = prior iy and ix = prior ix + 1 start with ix = 1 group by iy;

  • Rhialto (unregistered) in reply to memals
    memals:
    cat ROT13.LST | uniq -u > BIG.LST cat mword10/SINGLE.TXT | uniq -u >> BIG.LST cat BIG.LST | uniq --repeated > ROTRES.LST

    cat test.file | uniq --repeated

    Misuse of the cat command... 4 counts.

  • London Contractor Mart (unregistered) in reply to ChiefCrazyTalk
    ChiefCrazyTalk:
    Ie:
    TRWTF: I just tried it in Query Analyzer:

    Server: Msg 156, Level 15, State 1, Line 5 Incorrect syntax near the keyword 'WITH'. Server: Msg 170, Level 15, State 1, Line 10 Line 10: Incorrect syntax near ','. Server: Msg 170, Level 15, State 1, Line 16 Line 16: Incorrect syntax near ','. Server: Msg 170, Level 15, State 1, Line 42 Line 42: Incorrect syntax near 'PIVOT'.

    Works for me - SQL Server 2K5

    TRRWTF is that Ie reads this page and couldn't work out that he was attempting to run SQL from 2005+...Did you not see the PIVOT operator and realise? tut tut!

    captcha: persto - a bit like pesto but with peronality?

  • Gerg (unregistered)

    Incidentally, here's the same query for Postgres:

    WITH RECURSIVE Z(IX, IY, CX, CY, X, Y, I) AS ( SELECT IX::integer, IY::integer, X::float, Y::float, X::float, Y::float, 0::integer FROM (select -2.2 + 0.031 * i, i from generate_series(1,100) as i) as xgen(x,ix), (select -1.5 + 0.031 * i, i from generate_series(1,100) as i) 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::float AND I < 100 ) SELECT array_to_string(array_agg(SUBSTRING(' .,,,-----++++%%%%@@@@#### ', LEAST(GREATEST(I,1),27), 1)),'') FROM ( SELECT IX, IY, MAX(I) AS I FROM Z GROUP BY IY, IX ORDER BY IY, IX ) AS ZT GROUP BY IY ORDER BY IY ;

  • Gerg (unregistered) in reply to Gerg

    And again with a "[ code ]" tag around it:

    WITH RECURSIVE Z(IX, IY, CX, CY, X, Y, I) AS (
                    SELECT IX::integer, IY::integer, X::float, Y::float, X::float, Y::float, 0::integer
                    FROM (select -2.2 + 0.031 * i, i from generate_series(1,100) as i) as xgen(x,ix),
                         (select -1.5 + 0.031 * i, i from generate_series(1,100) as i) 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::float
                    AND I < 100
              )
        SELECT array_to_string(array_agg(SUBSTRING(' .,,,-----++++%%%%@@@@#### ', LEAST(GREATEST(I,1),27), 1)),'')
        FROM (
              SELECT IX, IY, MAX(I) AS I
              FROM Z
              GROUP BY IY, IX
              ORDER BY IY, IX
             ) AS ZT
        GROUP BY IY
        ORDER BY IY
    ;
    
  • Kuba (unregistered)

    Everything can be done in shell scripting, of course ;)

    http://www.dctsystems.co.uk/RenderMan/rensh.html

                                                 $$$$:
                                                ~####++
                                                 ~@@@+
    
                                       o        ~####++
                             ###PP$$$$##o       ~####++     ~PPPPPPPPPP++++      $             ,::
                             ###Po#####PPP      ~####++        :oooooo::       +$$$      o##~
                             ###Po~~   oPPPo    ~####++          P:oo        +++@@@@@    o##
                             ###Po~~   ~###     ~####++          :PP~       +++@@@@@@@   o##
                             ###PoPPPPP###       ####++       +++PPPPPP~  ::::@@@@@@@@@, o##
                             ###PP~~~~~P$        ####++       ++PPPPPPPP
                             ###PP
                             ###PP
                             ###PP
                              ###P
                              ###P
                              ###P
                              ###
    
  • Scuko (unregistered)

    Go to http://sql-ex.ru/?Lang=1, there you can find a lot more such SQL tasks.

  • Posti (unregistered)

    Sorry - the prize for MOST useless programming is still held by the creators of Vista.

  • csrster (unregistered) in reply to Charles400
    Charles400:
    It's an inkblot test. I see my wife's episiotomy.

    You're right, it does look like your wife's episiotomy!

  • Michael B (unregistered)

    All you have to do is remember that Benoit Mandelbrot's name is pronounced Ben-wah Maw-Dell-Brote and you'll never misspell it again!

  • Jno (unregistered) in reply to KenW
    KenW:
    zikko:
    Three different version!
    Great. Another loser heard from who has to get his kicks from criticizing typos. Yay.

    We adults with basic reading skills knew what he meant. Perhaps you should take a class.

    Well, not quite kicks, exactly. It's just that those of us with better than basic writing skills like to point and laugh. You know, peer pressure and all that.

  • Vic Tim (unregistered) in reply to Posti
    Posti:
    Sorry - the prize for MOST useless programming is still held by the creators of Vista.

    That's a bit harsh. Vista has proven to be a terrific platform for running many critical applications, such as Norton Antivirus, Spybot Search & Destroy, O&O Defrag, Ad-Aware, RegOptimizer, and it even comes with Windows Update and System Restore!! That's a hell of a lineup!

  • Daniel (unregistered)

    Here is a raytracer in Linq, which is sorta-like-real-sql-but-not-quite-cause-its-in-csharp-with-syntax-hightlighting-and-colorful

    http://tirania.org/blog/archive/2007/Nov-16.html

  • Schwab (unregistered)

    Wow, how freak'n cool is that! Dude it rocks!

  • Geoff Mcgehee (unregistered)

    What, no Julia set?

  • Hax Or (unregistered)

    And that's why, comments should be disabled.

    3 pages of nothing!

    The Mandelbrot trick looked great! Ignore the griefers.

  • Ben (unregistered) in reply to Someone You Know

    $WTF == "Well Thought, Functional";

  • (cs)

    Where do these people find the time to do these things?!

  • Paul Nicholls (unregistered)

    Ok, so maybe I went a little mad. I used this T-SQL as a base to construct a JS (and thus entirely client-side) ASCII-Art Mandelbrot explorer - allowing you to zoom in and out and move around the "image" at will. It's considerably quicker than the T-SQL version, though it's not instant (and speed will of course depend on your hardware). Enjoy!

  • Anonymous Coward (unregistered) in reply to Impressed
    Impressed:
    Jaw droppingly cool...

    But how do you get it to "zoom in" to one of the curls?

    Modify the values in the Cast() statements. The first value is the starting point and the second value is the step size for each of IX and IY.

  • (cs)

    It actually is pretty cool code. I'd give bonus point for the use of a CTE and PIVOT.

  • Earl Carey (unregistered)

    Holy cow... that my friend is not a stupid trick..its amazing...my reaction when i say the output...wtf

  • Earl Carey (unregistered) in reply to Vic Tim

    To funny for words

  • eric bloedow (unregistered)

    reminds me of a gag program i saw: type in a word, and it makes a "sine wave" on the screen with that word...

Leave a comment on “Stupid Coding Tricks: The T-SQL Mandelbrot”

Log In or post as a guest

Replying to comment #:

« Return to Article