3 # This file is part of NIT ( http://www.nitlanguage.org ).
4 # This program is public domain
6 # Task: Symmetric difference
7 # SEE: <http://rosettacode.org/wiki/Symmetric_difference>
9 module symmetric_difference
11 var a
= ["John", "Serena", "Bob", "Mary", "Serena"]
12 var b
= ["Jim", "Mary", "John", "Jim", "Bob"]
14 print
"Set A: {a.join(", ")}"
15 print
"Set B: {b.join(", ")}"
17 # Option 1: union of differences
18 var not_in_a
= new ArraySet[String]
21 not_in_a
.remove_all
(x
)
24 var not_in_b
= new ArraySet[String]
27 not_in_b
.remove_all
(x
)
30 var difference
= not_in_a
.clone
31 difference
.add_all
(not_in_b
)
33 print
"Symmetric difference: {difference.join(", ")}"
35 # Option 2: union minus intersection
36 var union
= new ArraySet[String]
40 var b1
= new ArraySet[String]
44 intersect
= new ArraySet[String]
46 intersect
= intersect
.intersection
(b1
)
48 var difference2
= union
.clone
50 difference2
.remove_all
(x
)
53 print
"Symmetric difference: {difference2.join(", ")}"