2 Added an general explanation separate from the code; added 7 characters in body
source | link

Well, I certainly didn't win, but this was a good brain workout! I may have picked a overly roundabout way of doing this, but it works! Basically, how it works is:

  1. The x-values of each column are calculated based on n. Then, the "active colums" that will contain the dots are filtered out. The columns are then zipped with the possibilities that they'll be chosen.

  2. The animation starts, and each frame, a loop is entered. Starting from the middle, each pair of columns is tried. Once one pair of columns is chosen, one column from the pair is randomly chosen.

  3. A dot is drawn at a random position within the chosen column, the inner loop exits, and a new frame begins.

See the breakdown belowungolfed code for an in-depth explanation:

Well, I certainly didn't win, but this was a good brain workout!

See the breakdown below for an explanation:

Well, I certainly didn't win, but this was a good brain workout! I may have picked a overly roundabout way of doing this, but it works! Basically, how it works is:

  1. The x-values of each column are calculated based on n. Then, the "active colums" that will contain the dots are filtered out. The columns are then zipped with the possibilities that they'll be chosen.

  2. The animation starts, and each frame, a loop is entered. Starting from the middle, each pair of columns is tried. Once one pair of columns is chosen, one column from the pair is randomly chosen.

  3. A dot is drawn at a random position within the chosen column, the inner loop exits, and a new frame begins.

See the ungolfed code for an in-depth explanation:

1
source | link

Clojure + Quil, 394 bytes

(use '[quil.core])(defn -main[n](let[w 999 h 100 c(/ w(-(* n 2)1))s(range 0 w c)a(vec(take-nth 2 s))v(fn[x](<(rand)x))q(fn[a b](+ a(rand-int(- b a))))g(for[i(range(int(/ n 2))-1 -1)][i(- n 1 i)])z(for[[j i](map vector(range 1(inc(count g)))g)][(/ 1(Math/pow 2 j))i])](defsketch m :size[w h]:draw #(loop[[[p i]& r]z](when p(if(v p)(let[o(a(rand-nth i))](point(q o(+ o c))(q 0 h)))(recur r)))))))

Well, I certainly didn't win, but this was a good brain workout!

Uses the Quil graphics library, which is essentially a Processing wrapper for Clojure.

Note, the golfed code doesn't produce the same animation as shown in the GIF. In the golfed code, the background is grey, and the window and dots are smaller. It has the same effect, it's just not as pretty.

GIF

See the breakdown below for an explanation:

(ns bits.golf.interference.interference
  (:require [quil.core :as q]))

; Canvas size
(def width 1800)
(def height 800)

(defn -main [n]
  (let [col-width (/ width (- (* n 2) 1))
        ; The left-most x of each column
        col-starts (range 0 width col-width)

        ; The columns that need to be drawn. Need "vec" so I can index it later.
        active-cols (vec (take-nth 2 col-starts))

        ; Function taking a decimal percentage, and returning whether or not it's satisfied.
        ; (chance? 0.5) would be used to simulate a coin toss.
        chance? (fn [perc] (< (rand) perc))

        ; Function that returns a random int between a and b
        r-int (fn [a b] (+ a (rand-int (- b a))))

        ; Generates index pairs for each complimentary column.
        indices (for [i (range (int (/ n 2)) -1 -1)]
                  [i (- n 1 i)])

        ; Zips each index pair from above with the chance that it will be" chosen"
        zipped-perc (for [[j i] (map vector (range 1 (inc (count indices))) indices)]
                      [(/ 1 (Math/pow 2 j)) i])]

    ; Animation boilerplate
    (q/defsketch Interference
      :size [width height]
      :draw
      ; The animation loop. It contains a loop over each complimentary column. It tries each column pair starting
      ;  from the middle, and works outward. Once it picks a pair of columns, it randomly chooses one of them.
      #(loop [[[p i] & r] zipped-perc]
         (when p
           ; Pick this column?
           (if (chance? p)
             ; Pick one of the column pairs
             (let [col (active-cols (rand-nth i))]
               ; Set the coloring and dot size
               (q/fill 0 0 0)
               (q/stroke-weight 5)
               ; And finally draw the dot
               (q/point (r-int col (+ col col-width))
                        (r-int 0 height)))

             ; If the column wasn't chosen, loop again to try the next one
             (recur r)))))))