Last active
April 13, 2019 02:19
-
-
Save datramt/d9940efd6db3227ca1aa7cbcb044424c to your computer and use it in GitHub Desktop.
generates a list of binary numbers and outputs one permutation as array of 1's & 0's
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 characters
define :genBinaryList do |n| | |
if n < 10 then | |
bl = [] | |
(0..(2**n -1)).each do |i| | |
bn = "%0#{n}b" % i | |
bl.push(bn) | |
end | |
return bl | |
else | |
return ["0"] | |
end | |
end | |
define :pickAPerm do |lop, n| | |
if lop.length > n then | |
ip = lop[n].split(//) | |
p = (0..ip.length-1).map do |n| ip[n].to_i end | |
return p | |
else | |
return ["0"] | |
end | |
end | |
define :genRhythm do |b, p| | |
p = pickAPerm(genBinaryList(b), p) | |
r = Array.new(b) do | e | p[e] end | |
return r.ring | |
end | |
rhythm = genRhythm(5, 13) | |
puts rhythm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment