Not having much of an idea what I was looking at there, I asked GPT-4 to explain this to me. Quite helpful (though it didn't seem to know what "pn" was for)
----
This K program appears to be defining three functions (point, line, and draw) that are related to drawing a mathematical pattern.
point function:
point: {(y;pn[f%20;0.3x;0.1y]-18sin ypi%100)}
This function takes two arguments: y and a variable function pn[f%20;0.3x;0.1y]. The function computes a value based on these arguments and returns the result. The expression (f%20;0.3x;0.1y) inside the pn function seems to generate new values for x and y based on the input x and y. The final result is multiplied by -18 sin(y * pi % 100), which can create interesting patterns depending on the input values.
line function:
line: {((30;x)+)'point[x]'!100}
This function takes a single argument, x, and computes the result of the point function for 100 evenly spaced values of y in the range 0 to 1 (by indexing the point function with x and each value in the range '0 to 99'). The results are then shifted by (30; x) to create a new set of coordinates. The function returns a list of these transformed coordinates.
draw function:
draw: {,(,/line'38+6*!16;cga;1)}
This function generates a sequence of 16 values (from 0 to 15) and multiplies each by 6, then adds 38. It then computes the line function for each of these values and concatenates the results. The final expression (cga; 1) seems to be related to the color or other visual properties of the pattern, but it is not clear from the given code snippet how it is being used.
Overall, this K program appears to be generating a list of coordinates for a complex pattern by applying transformations to a series of points. The specific pattern depends on the input values and the function pn, which is not fully defined in the provided code snippet.
pn is perlin noise. It's not part of the k standard, but provided by the iKe environment here. iKe is also providing 'f' which is the frame counter, and pi which is obviously pi.
It's a bit confused by the first function. It takes two arguments, x and y, and returns a tuple. The first value is 'y' and the second value is (sin(pi % 100 * y) * -18) * perlinNoise(frameNumber % 20, 0.3 * x, ), 0.1 * y). I might be a little off on that formula, it's been awhile since I've read k code.
Is the terseness of the programming language supposed to blow my mind? I know nothing of K, other than my quick STFW, which says it is some kind of proprietary language. What would that look like in say Python, I wonder?
for reference, golfed k code is typically 1/2 to 1/3 the size of golfed python code, which would be somewhat hard to read for a python programmer unfamiliar with golfing tricks. probably around 1/4 or 1/5 the size of ordinary python code.
the terseness isn't supposed to blow your mind, it's an artifact of k's iversonian heritage. the first iversonian language, apl, was originally intended as a kind of mathematical notation for computer programs, a compact notation for defining algorithms-as-mathematical-objects. imagine a programming teacher writing code on a chalkboard to the same degree a math teacher writes math on a chalkboard and the need for compact notation becomes obvious, i think.
Yeah my first reading of that title caught me off guard. "I don't think anyone needs that much, but you do you and also why is this on the HN frontpage?"
Doesn't actually do the thing that makes the Unknown Pleasures cover somewhat nontrivial difficult to render, which is to let foreground "waves" obscure background waves.
Indeed they are, as they're recordings of Pulsar CP 1919:
>“EIGHTY SUCCESSIVE PERIODS of the first pulsar observed, CP1919 (Cambridge pulsar at 19 hours 19 minutes right ascension), are stacked on top of one another using the average period of 1.33730 seconds in this computer-generated illustration produced at the Arecibo Radio Observatory in Puerto Rico. Although the leading edges of the radio pulses occur within a few thousandths of a second of the predicted times, the shape of the pulses is quite irregular. Some of this irregularity in radio reception is caused by the effects of transmission through the interstellar medium. The average pulse width is less than 50 thousandths of a second.” From “The Nature of Pulsars,” by Jeremiah P. Ostriker, Scientific American, January 1971.
You can click through in the 'Source' link in the tweet and see how it did that - by painting the image filled in white first then filled in black slightly lower.
(Re your point about the heights of the peaks - I actually adjusted my program to do this immediately after posting, and IIRC posted that too, but it was the first attempt that got all the likes/rts. I tended to do this all the time with these-just post the very first version that barely works, then regret it. I'm still doing that, this version of the vertigo poster... https://hachyderm.io/@bbcmicrobot@mastodon.me.uk/11010756246... was quickly followed by the fixed one... https://hachyderm.io/@bbcmicrobot@mastodon.me.uk/11010797875...)
Although it's worth noting that the information is somewhat outdated. Notably, the most recent version of K is K9 (referred to through its proprietary implementation called Shakti) although K3 (through Kona), K4 (through Q by KX systems), K5 (through Ngnk), and K6 (through oK) are still used as every few versions is somewhat different from what came before, including being rewritten from scratch.
Topics definitely come in waves. Sometimes I see link submissions that serve as support or rebuttals to other recent links. Sometimes an interesting comment even leads to related links hitting the front page.
check out oK[0] by John Earnest, who is the author of the content of this post.
it has a well-written manual and is a great jumping off point. the source is written in ~1000 lines of js. so you can look at how each primitive is implemented.
there is a k-enthusiast element.io server[1] where you can ask any question you like. folks are friendly!
EDIT: another commenter shared most of this info. oops :-) i'll add as well ngn-k browser repl[2] which has some docs and a fuller feature-set than oK. this is probably the most-used open source k right now. the author is active in the above element server, and still patches bugs and makes updates.
37 comments
[ 3.3 ms ] story [ 79.1 ms ] thread----
This K program appears to be defining three functions (point, line, and draw) that are related to drawing a mathematical pattern.
point function: point: {(y;pn[f%20;0.3x;0.1y]-18sin ypi%100)} This function takes two arguments: y and a variable function pn[f%20;0.3x;0.1y]. The function computes a value based on these arguments and returns the result. The expression (f%20;0.3x;0.1y) inside the pn function seems to generate new values for x and y based on the input x and y. The final result is multiplied by -18 sin(y * pi % 100), which can create interesting patterns depending on the input values.
line function: line: {((30;x)+)'point[x]'!100} This function takes a single argument, x, and computes the result of the point function for 100 evenly spaced values of y in the range 0 to 1 (by indexing the point function with x and each value in the range '0 to 99'). The results are then shifted by (30; x) to create a new set of coordinates. The function returns a list of these transformed coordinates.
draw function: draw: {,(,/line'38+6*!16;cga;1)} This function generates a sequence of 16 values (from 0 to 15) and multiplies each by 6, then adds 38. It then computes the line function for each of these values and concatenates the results. The final expression (cga; 1) seems to be related to the color or other visual properties of the pattern, but it is not clear from the given code snippet how it is being used.
Overall, this K program appears to be generating a list of coordinates for a complex pattern by applying transformations to a series of points. The specific pattern depends on the input values and the function pn, which is not fully defined in the provided code snippet.
It's a bit confused by the first function. It takes two arguments, x and y, and returns a tuple. The first value is 'y' and the second value is (sin(pi % 100 * y) * -18) * perlinNoise(frameNumber % 20, 0.3 * x, ), 0.1 * y). I might be a little off on that formula, it's been awhile since I've read k code.
The Eternal September of AI has come earlier than expected.
https://codegolf.stackexchange.com/questions/258335/shortest...
EDIT: Actually, my memory failed me. I just took a quick survey of some more questions and 4x or 5x seems typical for golfed vs golfed.
https://i.imgur.com/nlxdkGb.jpg
>“EIGHTY SUCCESSIVE PERIODS of the first pulsar observed, CP1919 (Cambridge pulsar at 19 hours 19 minutes right ascension), are stacked on top of one another using the average period of 1.33730 seconds in this computer-generated illustration produced at the Arecibo Radio Observatory in Puerto Rico. Although the leading edges of the radio pulses occur within a few thousandths of a second of the predicted times, the shape of the pulses is quite irregular. Some of this irregularity in radio reception is caused by the effects of transmission through the interstellar medium. The average pulse width is less than 50 thousandths of a second.” From “The Nature of Pulsars,” by Jeremiah P. Ostriker, Scientific American, January 1971.
https://blogs.scientificamerican.com/sa-visual/pop-culture-p...
https://twitter.com/bbcmicrobot/status/1604784926032740352
You can click through in the 'Source' link in the tweet and see how it did that - by painting the image filled in white first then filled in black slightly lower.(Re your point about the heights of the peaks - I actually adjusted my program to do this immediately after posting, and IIRC posted that too, but it was the first attempt that got all the likes/rts. I tended to do this all the time with these-just post the very first version that barely works, then regret it. I'm still doing that, this version of the vertigo poster... https://hachyderm.io/@bbcmicrobot@mastodon.me.uk/11010756246... was quickly followed by the fixed one... https://hachyderm.io/@bbcmicrobot@mastodon.me.uk/11010797875...)
Not particularly different, other than that I assume OP's challenge was to see how tiny they could make this and that might expand the code size.
[1] https://forums.somethingawful.com/showthread.php?threadid=37...
And Ike itself is not a bad environment to play around with K https://johnearnest.github.io/ok/ike/ike.html
It has a repl as well in: https://johnearnest.github.io/ok/ you can find source here: https://github.com/JohnEarnest/ok and manual here: https://github.com/JohnEarnest/ok/blob/gh-pages/docs/Manual....
If this is the entirety of K - https://kparc.com/k.txt it does fit on a single full-screen page.
it has a well-written manual and is a great jumping off point. the source is written in ~1000 lines of js. so you can look at how each primitive is implemented.
there is a k-enthusiast element.io server[1] where you can ask any question you like. folks are friendly!
EDIT: another commenter shared most of this info. oops :-) i'll add as well ngn-k browser repl[2] which has some docs and a fuller feature-set than oK. this is probably the most-used open source k right now. the author is active in the above element server, and still patches bugs and makes updates.
[0] https://github.com/JohnEarnest/ok
[1] https://matrix.to/#/#aplfarm-k:matrix.org
[2] https://ngn.codeberg.page/k/#
The cover was a stylized visualization of a fast Fourier transform, which this is replicating.