Created
May 1, 2014 06:12
-
-
Save shinokada/11445426 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# find number of item which has at least 3 numbers are the same | |
arr1 = [1, 2, 3, 4] | |
arr2 = [[2, 2, 2, 4],[1, 4, 3, 4],[1, 2, 1, 4],[1, 2, 3, 1],[2, 1, 3, 4]] | |
n = 0 | |
arr2.map{|e| e.zip(arr1).collect{| x, y| x==y}}.each do |e| | |
if e.count(true) >=3 | |
n += 1 | |
end | |
end | |
puts n | |
# Notes | |
# After zip | |
#[[[2, 1], [2, 2], [3, 3], [4, 4]], [[1, 1], [4, 2], [3, 3], [4, 4]], [[1, 1], [2, 2], [1, 3], [4, 4]], [[1, 1], [2, 2], [3, 3], [1, 4]], [[2, 1], [1, 2], [3, 3], [4, 4]]] | |
# | |
# After collect | |
# [[false, true, true, true], [true, false, true, true], [true, true, false, true], [true, true, true, false], [false, false, true, true]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment