derrick
2018-06-09 08:19:36 UTC
I am having a lot of trouble wrapping my head around this
I have an array of arrays of prime numbers.
I want to add a each prime number to this array.
example
I have
prime_ary = [[3, 5], [3, 7], [3, 11], [5, 11]]
add_ary = [57, 91, 109]
I would like to get an array of arrays like this
[[3,5, 57], [3, 7, 57], [3, 11, 57], [5, 11, 57], [3, 5, 91], [3, 7, 91], [3, 11, 91] ... ]
There should be 12 sub arrays in the array at the end. I have this function in an array class but it doesn't give me the result I would like. I have been working on this for a few days and feel like I have loosing the ability to think clearly. Any help is appreciated.
def add_ary_prime(numb)
solution_ary = []
numb.each do |rannumb|
solution_ary.push(self.map {|arr| arr << rannumb})
end
solution_ary
end
p prime_ary.add_ary_prime(add_ary)
sincerely,
Derrick
I have an array of arrays of prime numbers.
I want to add a each prime number to this array.
example
I have
prime_ary = [[3, 5], [3, 7], [3, 11], [5, 11]]
add_ary = [57, 91, 109]
I would like to get an array of arrays like this
[[3,5, 57], [3, 7, 57], [3, 11, 57], [5, 11, 57], [3, 5, 91], [3, 7, 91], [3, 11, 91] ... ]
There should be 12 sub arrays in the array at the end. I have this function in an array class but it doesn't give me the result I would like. I have been working on this for a few days and feel like I have loosing the ability to think clearly. Any help is appreciated.
def add_ary_prime(numb)
solution_ary = []
numb.each do |rannumb|
solution_ary.push(self.map {|arr| arr << rannumb})
end
solution_ary
end
p prime_ary.add_ary_prime(add_ary)
sincerely,
Derrick