2022.11.10 04:29 AM
In the forthcoming episode of the ArrayCast podcast our guest Michal Wallace of 1010data referred to an ad he had once placed on LinkedIn to recruit someone who would learn k3, an ancestor language of q.
In the job ad he showed the k3 code to print an ASCII version of the Mandelbrot set, reasoning that it would filter for devs who would take to k3.
The code looked so elegant that I translated it to q for your typing pleasure.
/ q example: Mandelbrot set
/ adapted from https://www.linkedin.com/pulse/want-work-k-1010data-michal-wallace
s:{(.[-]x*x),2*prd x} / complex square (x is R,Im pair)
m:{floor sqrt sum x*x} / magnitude (distance from origin)
d: 120 60 / dimensions of the picture
t: -88 -30 / camera translation
f: reciprocal 40 20 / scale factor
c: (,/:\:) . f * t + til each d / complex plane near mandelbrot set
z: d # enlist 0 0 / 3d array of zeroes in same shape
mb: c+ (s'')@ / Mandelbrot: s(z) + c
r: 1 _ 8 mb\z / collect 8 times
o: " 12345678"@ sum 2<m'''[r] / "color" by how soon point "escapes"
-1 "\n"sv flip o; / transpose and print the output
2022.11.10 06:00 PM
Very cool. I had to see this in action, here's a quick "animation" of the set converging - I recommend full screen viewing. Hypnotic stuff.
{r: 1 _ x mb\y;o: " 12345678abcdef"@ sum 2<m'''[r];-1 "\n"sv flip o;system"sleep 1";}[;z]each 1+til 15;
2022.11.10 11:41 AM
Very nice @SJT
Another great episode! 🙌
2022.11.10 06:00 PM
Very cool. I had to see this in action, here's a quick "animation" of the set converging - I recommend full screen viewing. Hypnotic stuff.
{r: 1 _ x mb\y;o: " 12345678abcdef"@ sum 2<m'''[r];-1 "\n"sv flip o;system"sleep 1";}[;z]each 1+til 15;
2022.11.11 02:16 AM
Oooooh – that is gorgeous!
EMEA
Tel: +44 (0)28 3025 2242
AMERICAS
Tel: +1 (212) 447 6700
APAC
Tel: +61 (0)2 9236 5700
KX. All Rights Reserved.
KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.