Skip to content

Instantly share code, notes, and snippets.

@kysnm
Created February 12, 2012 12:48
Show Gist options
  • Save kysnm/1808323 to your computer and use it in GitHub Desktop.
Save kysnm/1808323 to your computer and use it in GitHub Desktop.
離散数学読書会(@2012-02-12)
def myset(a1, a2)
h = Hash.new(0)
a1.each{|a| h[a] += 1}
a2.each{|a| h[a] += 1}
puts "a and b"
p h.select{|k, v| v == 2}.keys
puts "a or b"
p h.keys
puts "a - b"
p a1.select{|a| h[a] == 1}
end
myset([1, 3, -5, 8, -4], [7, -4, 2, 3, 8, -6, 5])
myset([1, 3, -5, 8, -4], [7, -2, 3, 2, -6, 9, -4])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment