Post Reply 
Mini-challenge: 3 lines of code
11-30-2016, 11:25 PM
Post: #1
Mini-challenge: 3 lines of code
 
Hi all:

What can we do with just 3 lines of code ? Why, the Mandelbrot set and assorted relatives, of course !

This mini-challenge isn't about producing a complex program which would output said fractals as suitably hi-res graphics with all kinds of bells and whistles but rather, just for fun, quite the opposite, namely:

To concoct the shortest, simplest program for your favorite HP calculator (not Excel, not C++, not Python, not Sharp, not TI, you get the drift) that will just output a recognizable likeness of the Mandelbrot set. The absolutely smallest size (in lines, statements, bytes or whatever) is paramount, features and speed are irrelevant.

Here's my entry for the HP-71B (+ Math ROM and some printer or display device, of course), let's see yours for your preferred HP calc ! (*cough* HP-41 plus printer *cough*)

- This will produce the ubiquitous Mandelbrot set in just 3 lines (11 statements), 122 bytes:

    1   COMPLEX C,Z @ FOR Y=-1 TO 1 STEP .05 @ FOR X=-2 TO .5 STEP .032
    2   C=(X,Y) @ Z=0 @ FOR I=1 TO 40 @ Z=Z*Z+C @ IF ABS(Z)>=2 THEN 'N'
    3   NEXT I @ 'N': PRINT CHR$(46+33*(I>40)); @ NEXT X @ PRINT @ NEXT Y

>RUN

...............................................................................
...............................................................................
...............................................................................
...........................................................O.O.................
........................................................OOOOOOO................
.......................................................OOOOOOO.................
........................................................OOOOOO.................
..................................................OO..OOOOOOOOOO...O...........
.............................................OOOO..OOOOOOOOOOOOOOOOO...O.......
.............................................OOOOOOOOOOOOOOOOOOOOOOOOOOOOO.....
..............................................OOOOOOOOOOOOOOOOOOOOOOOOOOO......
..........................................OO.OOOOOOOOOOOOOOOOOOOOOOOOOOO.......
............................................OOOOOOOOOOOOOOOOOOOOOOOOOOOOO......
.........................................OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO...
.........................................OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO....
..........................OO..OOOOO......OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO....
..........................OOOOOOOOOOOO..OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO....
.........................OOOOOOOOOOOOOO.OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO....
........................OOOOOOOOOOOOOOO.OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO.....
.....................OO.OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO.....
.OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO........
.....................OO.OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO.....
........................OOOOOOOOOOOOOOO.OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO.....
.........................OOOOOOOOOOOOOO.OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO....
..........................OOOOOOOOOOOO..OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO....
..........................OO..OOOOO......OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO....
.........................................OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO....
.........................................OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO...
............................................OOOOOOOOOOOOOOOOOOOOOOOOOOOOO......
..........................................OO.OOOOOOOOOOOOOOOOOOOOOOOOOOO.......
..............................................OOOOOOOOOOOOOOOOOOOOOOOOOOO......
.............................................OOOOOOOOOOOOOOOOOOOOOOOOOOOOO.....
.............................................OOOO..OOOOOOOOOOOOOOOOO...O.......
..................................................OO..OOOOOOOOOO...O...........
........................................................OOOOOO.................
.......................................................OOOOOOO.................
........................................................OOOOOOO................
...........................................................O.O.................
...............................................................................
...............................................................................
...............................................................................


- Replacing Z*Z by CONJ(Z)^2 and adjusting the ranges you get the beautiful Tricorn (aka Mandelbar) fractal:

    1   COMPLEX C,Z @ FOR Y=-1.3 TO 1.3 STEP .05 @ FOR X=-2 TO 1 STEP .038
    2   C=(X,Y) @ Z=0 @ FOR I=1 TO 40 @ Z=CONJ(Z)^2+C @ IF ABS(Z)>=2 THEN 'N'
    3   NEXT I @ 'N': PRINT CHR$(46+33*(I>40)); @ NEXT X @ PRINT @ NEXT Y

>RUN

...............................................................................
...............................................................................
.......................................................................O.......
.....................................................................OOO.......
.....................................................................OO........
...................................................................OOO.........
.................................................................OOOOOO........
.................................................................OOOOO.........
...............................................................OOOOOOO.........
...............................................................OOOOOOO.........
..............................................................OOOOOO...........
..............................................................OOOOOO...........
.............................................................OOOOOO............
............................................................OOOOOO.............
...........................................................OOOOOO..............
............................................................OOOO...............
..........................................................OOOOO................
..........................................................OOOOO................
.........................................................OOOO..................
.......................................................OOOOOO..................
.....................................................OOOOOOO...................
...................................................OOOOOOOOO...................
.................................................OOOOOOOOOOO...................
..............................................OOOOOOOOOOOOOO...................
........................OOOOOOO.O..........OOOOOOOOOOOOOOOOO...................
.....................OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO...................
.OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO...................
.....................OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO...................
........................OOOOOOO.O..........OOOOOOOOOOOOOOOOO...................
..............................................OOOOOOOOOOOOOO...................
.................................................OOOOOOOOOOO...................
...................................................OOOOOOOOO...................
.....................................................OOOOOOO...................
.......................................................OOOOOO..................
.........................................................OOOO..................
..........................................................OOOOO................
..........................................................OOOOO................
............................................................OOOO...............
...........................................................OOOOOO..............
............................................................OOOOOO.............
.............................................................OOOOOO............
..............................................................OOOOOO...........
..............................................................OOOOOO...........
...............................................................OOOOOOO.........
...............................................................OOOOOOO.........
.................................................................OOOOO.........
.................................................................OOOOOO........
...................................................................OOO.........
.....................................................................OO........
.....................................................................OOO.......
.......................................................................O.......
...............................................................................
...............................................................................


- finally, replacing Z*Z by (ABS(REPT(Z)),ABS(IMPT(Z)))^2 and adjusting ranges we get the deservedly famous Burning Ship fractal:

    1   COMPLEX C,Z @ FOR Y=-1.4 TO .6 STEP .05 @ FOR X=-2.3 TO 1.5 STEP .049 @ Z=0
    2   C=(X,Y) @ FOR I=1 TO 40 @ Z=(ABS(REPT(Z)),ABS(IMPT(Z)))^2+C @ IF ABS(Z)>=2 THEN 'N'
    3   NEXT I @ 'N': PRINT CHR$(46+33*(I>40)); @ NEXT X @ PRINT @ NEXT Y

>RUN

..............................................................................
...............................................................O..............
..............................................................................
..........................................................OO....O.............
........................................................OO.OOO.....O..........
.................................................O.O...OOO..OO.O..............
...........................................OO....OOOOOOOOOOOOOO...............
...............................O..........O.OO..OOOOOOOOOOOOOO................
....................................OOO.OOOOO..OOOOOOOOOOOOOO.................
.............................O.O.OO.O..OOOOOOOOOOOOOOOOOOOOO..................
...............................OO.O..OOOOOOOOOOOOOOOOOOOOOO...................
.............................O..OOOOOOOOOOOOOOOOOOOOOOOOOOO...................
.........................OO...O..OOOOOOOOOOOOOOOOOOOOOOOOO....................
.........................O...O..OOOOOOOOOOOOOOOOOOOOOOOOO.....................
...........................O..OOOOOOOOOOOOOOOOOOOOOOOOOOO.....................
.........................OO...OOOOOOOOOOOOOOOOOOOOOOOOOO......................
........................O.OOOOOOOOOOOOOOOOOOOOOOOOOOOOOO......................
..........................OOOOOOOOOOOOOOOOOOOOOOOOOOOOO.......................
........................O.OOOOOOOOOOOOOOOOOOOOOOOOOOOO........................
........................OOOOOOOOOOOOOOOOOOOOOOOOOOOOOO........................
.....................OO.OOOOOOOOOOOOOOOOOOOOOOOOOOOOOO........................
....................O.OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO.........................
..................OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO.........................
..................OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO.........................
.................OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO.........................
.................OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO.........................
.................OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO.........................
.................OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO.........................
.......OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO.........................
...........................OOOOOOOOOOOOOOOOOOOOOOOOOOO........................
........................................OOOOOOOOOOOOOOO.......................
..........................................OOOOOOOOOOOOOO......................
............................................OOOOOOOOOOOO......................
..............................................OOOOOOOOOO......................
...............................................OOOOOOOOO......................
.................................................OOOOOOO......................
..................................................OOOOO.......................
....................................................OO........................
..............................................................................
..............................................................................
..............................................................................

Regards.
V.
 

  
All My Articles & other Materials here:  Valentin Albillo's HP Collection
 
Visit this user's website Find all posts by this user
Quote this message in a reply
12-01-2016, 12:42 AM
Post: #2
RE: Mini-challenge: 3 lines of code
The second image reminded me of a Klingon Bird of Prey ship. :-)
Find all posts by this user
Quote this message in a reply
12-01-2016, 09:25 PM
Post: #3
RE: Mini-challenge: 3 lines of code
(12-01-2016 12:42 AM)cruff Wrote:  The second image reminded me of a Klingon Bird of Prey ship. :-)

Me too !

V.

  
All My Articles & other Materials here:  Valentin Albillo's HP Collection
 
Visit this user's website Find all posts by this user
Quote this message in a reply
12-01-2016, 09:56 PM
Post: #4
RE: Mini-challenge: 3 lines of code
(12-01-2016 09:25 PM)Valentin Albillo Wrote:  
(12-01-2016 12:42 AM)cruff Wrote:  The second image reminded me of a Klingon Bird of Prey ship. :-)

Me too !

V.
+1 Smile
Find all posts by this user
Quote this message in a reply
12-03-2016, 12:26 AM (This post was last modified: 12-03-2016 12:35 AM by Geoff Quickfall.)
Post: #5
RE: Mini-challenge: 3 lines of code
Beautiful, but image 2 is definitely a Xeelee Nightfighter; a definite Kardashev 3 civilization.

:-)
Find all posts by this user
Quote this message in a reply
12-03-2016, 08:22 AM
Post: #6
RE: Mini-challenge: 3 lines of code
Valentin, this is really beautiful challenge - but: Saturday morning (in CET), I'm hungry, I want my coffee too, so I guess the best answer now:

If you do nothing, you can't go wrong.

HP-15C version:

LBL A
RTN


2 lines only, usage: [f] [USER] [A]

Wink Csaba
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)