-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (40 loc) · 1 KB
/
main.go
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
package main
import (
"flag"
"fmt"
"strings"
mapset "github.com/deckarep/golang-set"
)
func main() {
a := flag.String("a", "", "set A (comma-separated list")
b := flag.String("b", "", "set B (comma-separated list")
sep := flag.String("s", ",", "list separator")
difference := flag.Bool("d", false, "difference (A \\ B)")
intersection := flag.Bool("i", false, "insersection (A ∩ B)")
union := flag.Bool("u", false, "union (A ∪ B)")
flag.Parse()
setA := mapset.NewSet()
for _, el := range strings.Split(*a, *sep) {
setA.Add(el)
}
setB := mapset.NewSet()
for _, el := range strings.Split(*b, *sep) {
setB.Add(el)
}
if !*difference && !*intersection && !*union {
fmt.Printf("Set A: %v\n", setA)
fmt.Printf("Set B: %v\n", setB)
}
if *difference {
result := setA.Difference(setB)
fmt.Printf("\\: %v\n", result)
}
if *intersection {
result := setA.Intersect(setB)
fmt.Printf("∩: %v\n", result)
}
if *union {
result := setA.Union(setB)
fmt.Printf("∪: %v\n", result)
}
}