I'm reviewing high school mathematics, so I tried to solve it using Ruby and Python.
Assuming that the sample space S = {1, 2, 3, ..., 98, 99, 100}, the multiple of 3 is event A, and the multiple of 5 is event B, the multiple of 3 or 5 Cards that are multiples of
E1 = A \cup B
--n (A) = multiples of 3 = 100/3 = 33 sheets --n (B) = multiples of 5 = 100/5 = 20 sheets --n (A \ cap B) Multiples of 3 and multiples of 5 = Numbers of multiples of 15 = 100/15 = 6 sheets
So
n(E1) = n(A \cup B)
= n(A) + n(B) - n(A \cap B)
= 33 + 20 - 6
= 47
So a card that is a multiple of 3 but not a multiple of 5
n(E) = n(E1) - n(B)
= 47 - 20
= 27
The probability of drawing a card that is a multiple of 3 but not a multiple of 5
n(E) / n(S)
= 27/100
The union can be calculated with |. The intersection is &.
> s = (1..100).to_a
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
> a = []
=> []
> s.to_a.each{|i|
* a << i if i %3 == 0
> }
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
> b = []
=> []
> s.to_a.each{|i|
* b << i if i % 5 == 0
> }
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
> e1 = a | b
=> [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75, 78, 81, 84, 87, 90, 93, 96, 99, 5, 10, 20, 25, 35, 40, 50, 55, 65, 70, 80, 85, 95, 100]
> e = e1.length - b.length
=> 27
> e.to_f / 100
=> 0.27
The union can be calculated with the union () function. The intersection is the interrupt () function.
>>> a = set(range(3,101,3))
>>> b = set(range(5,101,5))
>>> e1 = a.union(b)
>>> e = len(e1) - len(b)
>>> float(e)/100
0.27
Addendum) The union can also be calculated with |.
>>> a = set(range(3,101,3))
>>> b = set(range(5,101,5))
>>> e1 = a | b
>>> e = len(e1) - len(b)
>>> float(e)/100
0.27
I also tried using Sympy.
>>> from sympy import FiniteSet
>>> ma = range(3,101,3)
>>> mb = range(5,101,5)
>>> a = FiniteSet(*ma)
>>> b = FiniteSet(*mb)
>>> e1 = a.union(b)
>>> e = len(e1) - len(b)
>>> float(e)/100
0.27
range () function Easy.
-Qiita Formula Cheat Sheet -[Python aggregate type](http://kaworu.jpn.org/python/Python aggregate type) -Introduction to Mathematics Starting with Python (Book)