I'm having a few issues with my code and what I am trying to do. I've googled this most of the day. I apologize if this is simple and the solution is simple, well I am looking for a solution I prefer a full explanation.
My code thus far:
a1 = [ 4, 6, 7, 8, 10, 13, 14, 15, 17, 21, 24, 45, 48, 61]
a2 = [ 5, 10, 14, 18, 24, 25, 33, 34, 40, 45, 47, 50, 52, 54]
a3 = [ 1, 5, 12, 17, 23, 24, 25, 29, 33, 39, 40, 44, 46, 48]
a4 = [ 5, 16, 18, 20, 31, 39, 41, 42, 43, 55, 57, 60, 62, 63]
a5 = [ 2, 7, 18, 26, 33, 36, 38, 43, 44, 45, 50, 51, 52, 55]
a6 = [ 2, 12, 14, 15, 18, 24, 32, 35, 41, 43, 46, 47, 48, 51]
a7 = [ 4, 12, 13, 15, 17, 18, 19, 23, 26, 32, 33, 35, 40, 47]
all_arrays = [a1, a2, a3, a4, a5, a6, a7]
total = Array.new
fun = Array.new
b = Array.new
all_arrays.map do |arr3|
fun = [arr3.include?(41 & 43)] #.count(true)
total = [fun.count(true)]
Here I'm trying to see if 41 and 43 occur together in an array, which they do in a4 and a6. Now I want to be able to count how many times they occur together. If I was to puts total the out put would be 0001010.
If I output puts fun I would get false, false, false, true, false, true. I want to be able to count the trues or the 1's, So that I would have a total of how many times 41 and 43 occur.
I don't understand how to turn an out put into an array? I'm sure that total = [fun.count(true)] is not correct. But it works? sort of.
Should I have created a class?
counts = Hash.new(0)
total.each do |color|
counts[color] += 1
#puts counts
#puts total.count
#total.uniq.each do |elem|
#puts "#{elem}\t#{total.count(elem)}"
#end
end
Here is code that appears on google and other sites, including stackoverflow, during my research. I have looked at the doc's and the api; I do not yet understand the logic and syntax of the language, so reading a bunch and taking some online classes hasn't worked. I'm hoping to learn by doing, But currently this is new to me and I'm helping my son with a after school project. I would like to learn this so I am teach him. Thank you for your help.
a = Array.newis the same asa = []. The latter is generally used. Similarly,h = Hash.newis the same ash = {}and again, the latter is normally used.