Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
51
Task/Set/AutoHotkey/set-1.ahk
Normal file
51
Task/Set/AutoHotkey/set-1.ahk
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
test(Set,element){
|
||||
for i, val in Set
|
||||
if (val=element)
|
||||
return true
|
||||
return false
|
||||
}
|
||||
|
||||
Union(SetA,SetB){
|
||||
SetC:=[], Temp:=[]
|
||||
for i, val in SetA
|
||||
SetC.Insert(val), Temp[val] := true
|
||||
for i, val in SetB
|
||||
if !Temp[val]
|
||||
SetC.Insert(val)
|
||||
return SetC
|
||||
}
|
||||
|
||||
intersection(SetA,SetB){
|
||||
SetC:=[], Temp:=[]
|
||||
for i, val in SetA
|
||||
Temp[val] := true
|
||||
for i, val in SetB
|
||||
if Temp[val]
|
||||
SetC.Insert(val)
|
||||
return SetC
|
||||
}
|
||||
|
||||
difference(SetA,SetB){
|
||||
SetC:=[], Temp:=[]
|
||||
for i, val in SetB
|
||||
Temp[val] := true
|
||||
for i, val in SetA
|
||||
if !Temp[val]
|
||||
SetC.Insert(val)
|
||||
return SetC
|
||||
}
|
||||
|
||||
subset(SetA,SetB){
|
||||
Temp:=[], A:=B:=0
|
||||
for i, val in SetA
|
||||
Temp[val] := true , A++
|
||||
for i, val in SetB
|
||||
if Temp[val]{
|
||||
B++
|
||||
IfEqual, A, %B%, return 1
|
||||
} return 0
|
||||
}
|
||||
|
||||
equal(SetA,SetB){
|
||||
return (SetA.MaxIndex() = SetB.MaxIndex() && subset(SetA,SetB)) ? 1: 0
|
||||
}
|
||||
42
Task/Set/AutoHotkey/set-2.ahk
Normal file
42
Task/Set/AutoHotkey/set-2.ahk
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
A:= ["apple", "cherry", "elderberry", "grape"]
|
||||
B:= ["banana", "cherry", "date", "elderberry", "fig"]
|
||||
C:= ["apple", "cherry", "elderberry", "grape", "orange"]
|
||||
D:= ["apple", "cherry", "elderberry", "grape"]
|
||||
E:= ["apple", "cherry", "elderberry"]
|
||||
M:= "banana"
|
||||
|
||||
Res =
|
||||
(
|
||||
A:= ["apple", "cherry", "elderberry", "grape"]
|
||||
B:= ["banana", "cherry", "date", "elderberry", "fig"]
|
||||
C:= ["apple", "cherry", "elderberry", "grape", "orange"]
|
||||
D:= ["apple", "cherry", "elderberry", "grape"]
|
||||
E:= ["apple", "cherry", "elderberry"]
|
||||
M:= "banana"
|
||||
|
||||
)
|
||||
|
||||
Res .= "`nM is " (test(A,M)?"":"not ") "an element of Set A"
|
||||
Res .= "`nM is " (test(B,M)?"":"not ") "an element of Set B"
|
||||
|
||||
Res .= "`nUnion(A,B) = "
|
||||
for i, val in Union(A,B)
|
||||
Res.= (A_Index=1?"`t":", ") val
|
||||
|
||||
Res .= "`nintersection(A,B) = "
|
||||
for i, val in intersection(A,B)
|
||||
Res.= (A_Index=1?"`t":", ") val
|
||||
|
||||
Res .= "`ndifference(A,B) = "
|
||||
for i, val in difference(A,B)
|
||||
Res.= (A_Index=1?"`t":", ") val
|
||||
|
||||
Res .= "`n`nA is " (subset(A,C)?"":"not ") "a subset of Set C"
|
||||
Res .= "`nA is " (subset(A,D)?"":"not ") "a subset of Set D"
|
||||
Res .= "`nA is " (subset(A,E)?"":"not ") "a subset of Set E"
|
||||
|
||||
Res .= "`n`nA is " (equal(A,C)?"":"not ") "a equal to Set C"
|
||||
Res .= "`nA is " (equal(A,D)?"":"not ") "a equal to Set D"
|
||||
Res .= "`nA is " (equal(A,E)?"":"not ") "a equal to Set E"
|
||||
|
||||
MsgBox % Res
|
||||
Loading…
Add table
Add a link
Reference in a new issue