-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsets.vbs
More file actions
97 lines (92 loc) · 2.3 KB
/
sets.vbs
File metadata and controls
97 lines (92 loc) · 2.3 KB
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
option explicit
sub main()
dim a, b
a = array(1, 2, 2, 2, 4, 5, 7)
b = array(2, 2, 5, 5, 8, 8)
wscript.echo "A => { " & join(a) & " } B => { " & join(b) & " }"
union a, b
intersection a, b
minus a, b
end sub
sub union(byref a, byref b)
' wscript.echo lbound(a), ubound(a)
dim i, j, iend, jend, prev
i = 0 : j = 0 : iend = ubound(a) : jend = ubound(b) : prev = -1
do while (i <= iend) and (j <= jend)
if a(i) < b(j) then
if a(i) <> prev then
wscript.stdout.write a(i)
end if
prev = a(i)
i = i+1
elseif b(j) < a(i) then
if b(j) <> prev then
wscript.stdout.write b(j)
end if
prev = b(j)
j = j+1
else
if a(i) <> prev then
wscript.stdout.write a(i)
end if
prev = a(i)
i = i+1
j = j+1
end if
loop
for i = i to iend
if a(i) <> prev then
wscript.stdout.write a(i)
end if
prev = a(i)
next
for j = j to jend
if b(j) <> prev then
wscript.stdout.write b(j)
end if
prev = b(j)
next
wscript.stdout.writeline
end sub
sub intersection(byref a, byref b)
dim i, j, iend, jend, prev
i = 0 : j = 0 : iend = ubound(a) : jend = ubound(b) : prev = -1
do while (i <= iend) and (j <= jend)
if a(i) < b(j) then
i = i+1
elseif b(j) < a(i) then
j = j+1
else
if a(i) <> prev then
wscript.stdout.write a(i)
end if
prev = a(i)
i = i+1
j = j+1
end if
loop
wscript.stdout.writeline
end sub
sub minus(byref a, byref b)
dim i, lo, hi, mid, prev
prev = -1
for i = 0 to ubound(a)
lo = 0
hi = ubound(b)
mid = lo+(hi-lo)\2
do while (lo < hi) and (a(i) <> b(mid))
if a(i) < b(mid) then
hi = mid-1
else
lo = mid+1
end if
mid = lo+(hi-lo)\2
loop
if (a(i) <> b(mid)) and (a(i) <> prev) then
wscript.stdout.write a(i)
prev = a(i)
end if
next
wscript.stdout.writeline
end sub
call main()