Ruby array manipulation (Ruby 1.8 and Rails 2.2) -


I am trying to write a method to manipulate an array in Ruby. I am trying to generate all the sequences of an array where each item is closely replaced with external items. An example ...

Input given:

  

desired output:

  newArr = [["a",  "[" A "," * "," * "]," b "," c "], [" a "," b "," * "], [" a " ["*", "*", "C"], ["*", "*", "[" * "", "b", "c"], ["*", "b", "*"], Any help would be greatly appreciated. Thanks!   

I can not understand the order of your example I am ignoring either, here is a line in a solution:

  (0 ... (2 ** a.size)). Map {| x | (0. ..a.size) .map {| y | x and amp; 2 ** y == 0? A [y]: val}}  

Comments