Mini-challenge: 3 lines of code - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: General Forum (/forum-4.html) +--- Thread: Mini-challenge: 3 lines of code (/thread-7344.html) |
Mini-challenge: 3 lines of code - Valentin Albillo - 11-30-2016 11:25 PM 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. RE: Mini-challenge: 3 lines of code - cruff - 12-01-2016 12:42 AM The second image reminded me of a Klingon Bird of Prey ship. :-) RE: Mini-challenge: 3 lines of code - Valentin Albillo - 12-01-2016 09:25 PM (12-01-2016 12:42 AM)cruff Wrote: The second image reminded me of a Klingon Bird of Prey ship. :-) Me too ! V. RE: Mini-challenge: 3 lines of code - aurelio - 12-01-2016 09:56 PM (12-01-2016 09:25 PM)Valentin Albillo Wrote:+1(12-01-2016 12:42 AM)cruff Wrote: The second image reminded me of a Klingon Bird of Prey ship. :-) RE: Mini-challenge: 3 lines of code - Geoff Quickfall - 12-03-2016 12:26 AM Beautiful, but image 2 is definitely a Xeelee Nightfighter; a definite Kardashev 3 civilization. :-) RE: Mini-challenge: 3 lines of code - Csaba Tizedes - 12-03-2016 08:22 AM 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] Csaba |