Last active
March 22, 2016 19:17
Revisions
-
unthingable revised this gist
Jan 27, 2014 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,8 +5,8 @@ (defn recombine "Distribute tail: [[1] [1] [1] [0] [0]] -> [[1 0] [1 0] [1]]" ([a b] [a b]) ([a b c] [a b c]) ([a b c & more] (let [s (concat [a b c] more) [head tail] (split-seq s) @@ -20,7 +20,7 @@ (defn E [k n] "Evenly distribute K beats among N subdivisions" (let [seed (concat (repeat k [1]) (repeat (- n k) [0]))] (flatten (apply recombine seed)))) -
unthingable revised this gist
Jan 27, 2014 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,10 @@ (defn split-seq [s] "Extract a tail of all same elements: [1 1 0 0 0] -> [[1 1] [0 0 0]]" (let [l (last s)] (split-with #(not= l %) s))) (defn recombine "Distribute tail: [[1] [1] [1] [0] [0]] -> [[1 0] [1 0] [1]]" ([a b] (list a b)) ([a b c] (list a b c)) ([a b c & more] @@ -17,6 +19,7 @@ (drop r-len (drop-last r-len s)))))))) (defn E [k n] "Evenly distribute K beats among N subdivisions" (let [seed (concat (repeat k '(1)) (repeat (- n k) '(0)))] (flatten (apply recombine seed)))) -
unthingable created this gist
Jan 27, 2014 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ (defn split-seq [s] (let [l (last s)] (split-with #(not= l %) s))) (defn recombine ([a b] (list a b)) ([a b c] (list a b c)) ([a b c & more] (let [s (concat [a b c] more) [head tail] (split-seq s) recombined (map concat head tail) r-len (count recombined)] (if (empty? head) ;; even pattern (all supbatterns same) s (apply recombine (concat recombined (drop r-len (drop-last r-len s)))))))) (defn E [k n] (let [seed (concat (repeat k '(1)) (repeat (- n k) '(0)))] (flatten (apply recombine seed)))) ;; output > (E 3 6) (1 0 1 0 1 0) > (E 3 8) (1 0 0 1 0 0 1 0) > (E 4 6) (1 0 1 1 0 1) > (E 3 8) (1 0 0 1 0 0 1 0) > (E 2 6) (1 0 0 1 0 0) > (E 3 4) (1 0 1 1) > (E 5 11) (1 0 0 1 0 1 0 1 0 1 0)