Skip to content

Instantly share code, notes, and snippets.

@datramt
Last active April 13, 2019 02:19
Show Gist options
  • Save datramt/d9940efd6db3227ca1aa7cbcb044424c to your computer and use it in GitHub Desktop.
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
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