Welcome to MSDN Blogs Sign in | Join | Help

Mandelbrot One-liner

WaiKin Wong sent me a Mandelbrot one-liner:

$i=$j=$r=$x=$y=[float]-16; while(($y++) -lt 15) {for($x=0; ($x++) -lt 84; write-host (" .:-;!/>`)|&IH%*#"[$k -band 15]) -nonewline){$i=$k=$r=[float]0;do{$j=$r*$r-$i*$i-2+$x/25;$i=2*$r*$i+$y/10;$r=$j} while (($j*$j+$i*$i) -lt 11 -band ($k++) -lt 111)}" "}


This produces the following results:

 

:::::::::::::------------------------------------------------:::::::::::::::::::::::
:::::::::--------------------------------------------------------:::::::::::::::::::
:::::----------------------------------;;;;;;;;;;;-------------------:::::::::::::::
:::-----------------------------;;;;;;;;;;;;;;;;;;;;;;;;---------------:::::::::::::
---------------------------;;;;;;;;;;;;;!!!/-%//!!!;;;;;;;;---------------::::::::::
------------------------;;;;;;;;;;;;;!!!!//>)I#&H /!!!;;;;;;;;--------------::::::::
--------------------;;;;;;;;;;;;;!!!!!!//>)|&:# &)>//!!!!;;;;;;;--------------::::::
----------------;;;;;;;;;;;;;!!!!!!////>>)&-    /-&>>///!!!!;;;;;--------------:::::
------------;;;;;;;;;;;;!!!!!!!//>)|H))|&&H      %I||)>>>>#/!!;;;;;-------------::::
--------;;;;;;;;;;!!!!!!!!!!///>>|%-   &             .H%I#H >!!;;;;;-------------:::
-----;;;;;;;;;!!!!///////////>>)&:%-                      H)>/!!;;;;;-------------::
-;;;;;;;;;;!!!!/>&&)>>))))>>))|&*.                        *&I>/!!;;;;--------------:
;;;;;;;;!!!!!//>>|I.-!H#;% I&&I>                           #|>/!!;;;;;--------------
;;;;;!!!!!///>>)|H%-;                                       I//!!;;;;;--------------
!!!!/////>>>)|%*:##           #                            |>/!!!;;;;;;-------------
                                                        .I|>//!!!;;;;;;-------------
!!!!/////>>>)|%*:##           #                            |>/!!!;;;;;;-------------
;;;;;!!!!!///>>)|H%-;                                       I//!!;;;;;--------------
;;;;;;;;!!!!!//>>|I.-!H#;% I&&I>                           #|>/!!;;;;;--------------
-;;;;;;;;;;!!!!/>&&)>>))))>>))|&*.                        *&I>/!!;;;;--------------:
-----;;;;;;;;;!!!!///////////>>)&:%-                      H)>/!!;;;;;-------------::
--------;;;;;;;;;;!!!!!!!!!!///>>|%-   &             .H%I#H >!!;;;;;-------------:::
------------;;;;;;;;;;;;!!!!!!!//>)|H))|&&H      %I||)>>>>#/!!;;;;;-------------::::
----------------;;;;;;;;;;;;;!!!!!!////>>)&-    /-&>>///!!!!;;;;;--------------:::::
--------------------;;;;;;;;;;;;;!!!!!!//>)|&:# &)>//!!!!;;;;;;;--------------::::::
------------------------;;;;;;;;;;;;;!!!!//>)I#&H /!!!;;;;;;;;--------------::::::::
---------------------------;;;;;;;;;;;;;!!!/-%//!!!;;;;;;;;---------------::::::::::
:::-----------------------------;;;;;;;;;;;;;;;;;;;;;;;;---------------:::::::::::::
:::::----------------------------------;;;;;;;;;;;-------------------:::::::::::::::
:::::::::--------------------------------------------------------:::::::::::::::::::
:::::::::::::------------------------------------------------:::::::::::::::::::::::

Thanks for sharing WaiKin!

 

Jeffrey Snover [MSFT]
Windows PowerShell/MMC Architect
Visit the Windows PowerShell Team blog at:    http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at:  http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

Published Thursday, December 28, 2006 10:04 PM by PowerShellTeam

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Mandelbrot One-liner

That's cheating - it's concatenated.  It's just a big run-on sentence.

Still - it's pretty cool.

I wonder if we can write a one-liner that can get a robot to Mars.  Hmmm... World Domination...Hmmm...COntrol!!!!.....I wan't control!   PowerSHell Rules!!!!  He! He! He!.

Thursday, December 28, 2006 9:51 PM by JIm V

# re: Mandelbrot One-liner

> That's cheating - it's concatenated.  It's just a big run-on sentence.

Busted.  :-)

Jeffrey Snover [MSFT]

Windows PowerShell/MMC Architect

Visit the Windows PowerShell Team blog at:    http://blogs.msdn.com/PowerShell

Visit the Windows PowerShell ScriptCenter at:  http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

Thursday, December 28, 2006 10:24 PM by PowerShellTeam

# re: Mandelbrot One-liner

How about some PowerShell quines?

Friday, December 29, 2006 7:20 AM by Mike

# re: Mandelbrot One-liner

okay, that's the coolest thing i've seen in a while. top stuff.

Friday, December 29, 2006 8:49 PM by lb

# re: Mandelbrot One-liner

Somewhat related to this: I've been doing some performance comparisons with PowerShell and other scripting solutions on Windows (JScript.NET, WSF).

I came across a non-one-line version of the mandelbrot generator and used it for the tests.

http://ps1.soapyfrog.com/blog/files/powershell_is_slow.html

Monday, January 01, 2007 7:20 AM by Adrian Milliner

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker