Inter-array permutations in Ruby

I don't really have a better name for this. It's also not completely clean, but it works. I had, almost a year ago (362 days ago), written a blog post about <a href="http://trevoke.net/blog/2008/12/20/lexicographic-permutations-in-ruby">lexicographic permutations</a>. That was about permutations of elements within one array. Someone on ruby-forum asked about permutations between multiple arrays. I <a href="http://stackoverflow.com/questions/710670/c-permutation-of-an-array-of-arraylists">found something in C#</a>, which I was happy to transcribe to Ruby and tweak a little.

Random constrained permutations in Ruby

Look, Ma, these are my baby steps in algorithms! 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 # list is the elements to be permuted # y is the number of results desired # z is the number of elements per result # equalizer keeps track of who got used how many times def constrained_permutations list, y, z list.

On re-reading old code

I came across this beauty in some old code of mine: 1 2 3 4 5 6 7 def same_modality? list check = list[0][0] list.each do |i| return false if check != i[0] end return true end This was "necessary" because I got an array of one-element arrays back, and I wanted to check whether or not that one element was the same across the array.

Monday night training

I received an email from sensei on Monday (sent to every student) - if you'll be here tonight, bring your fighting gear. Uh-oh. Her sensei was there and taught a few classes, including the adults. The entire class turned out to be pretty much a blur of drills. I'll be able to dredge them out of my body memory, I think. A drill about basics - chain two basics together, using shifting.