News for hackers. Stuff that matters.
Re:Random walk in 2 lines of J by mlochbaum on Saturday October 15, 2022 @08:35PM (#33220007)
Yes, it's a pretty simple example. Something fun along the same lines, plotting pink noise (random walk is Brownian, or brown noise) in two lines of BQN: https://mlochbaum.github.io/BQN/try.html#code=UmFuZCDihpAgLe...

    Rand ← -⟜¬ •rand.Range⟜0
    •Plot {+` 𝕩 ↑ ⥊∘⍉∘≍´⌽ -⟜«∘Rand¨ (1⌈↕∘⌈)⌾(2⋆⁼⊢)2⌈𝕩} 500
A slightly spread out translation of the function to J below. The idea is to take lengths 2 2 4 8 16... up to the required length, and then repeatedly interleave the two smallest ones to get a fractal pattern. The interleaved values are differences of white noise, and a final sum undoes these differences to leave a sum of white noise at several different frequencies.

    pink =: {{
      len   =. (1>.i.@>.)&.:(2&^.) 2>.y
      diffs =. (2-~/\0,[:(--.)?@$&0)&.> len
      +/\ y {. >,@,.&.>/|. diffs
    }}
Adapted from [0], which I was able to simplify some when I ported it from an earlier J version [1]. I think having the whole algorithm there at once was definitely helpful in figuring out what I meant to do and writing it more cleanly.

[0] https://github.com/mlochbaum/BQNoise/blob/master/tracker.bqn...

[1] https://github.com/mlochbaum/JSound/blob/master/makedrums.ij...

Re:Random walk in 2 lines of J by jonahx on Saturday October 15, 2022 @09:35PM (#33220328)
Also worth pointing the example from the problem can be written more succintly:

    plot+/\_1+2*?100#2
Re:Random walk in 2 lines of J by raydiatian on Sunday October 16, 2022 @06:45AM (#33222631)
I now remember what code looks like to somebody who has never coded.

What an awful looking language. Laughing my ass off.

Re:Random walk in 2 lines of J by razetime on Sunday October 16, 2022 @07:14AM (#33222751)
Seeing this snide and shallow comment, I think you could benefit from expanding your mind by learning J: http://www.jsoftware.com/help/learning/contents.htm
Re:Random walk in 2 lines of J by raydiatian on Sunday October 16, 2022 @07:15AM (#33222757)
Pass