September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
30
Task/Symmetric-difference/Phix/symmetric-difference.phix
Normal file
30
Task/Symmetric-difference/Phix/symmetric-difference.phix
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
function Union(sequence a, sequence b)
|
||||
for i=1 to length(a) do
|
||||
if not find(a[i],b) then
|
||||
b = append(b,a[i])
|
||||
end if
|
||||
end for
|
||||
return b
|
||||
end function
|
||||
|
||||
function Difference(sequence a, sequence b)
|
||||
sequence res = {}
|
||||
for i=1 to length(a) do
|
||||
if not find(a[i],b)
|
||||
and not find(a[i],res) then
|
||||
res = append(res,a[i])
|
||||
end if
|
||||
end for
|
||||
return res
|
||||
end function
|
||||
|
||||
function Symmetric_Difference(sequence a, sequence b)
|
||||
return Union(Difference(a, b), Difference(b, a))
|
||||
end function
|
||||
|
||||
sequence a = {"John", "Serena", "Bob", "Mary", "Serena"},
|
||||
b = {"Jim", "Mary", "John", "Jim", "Bob"}
|
||||
?Symmetric_Difference(a,a)
|
||||
?Symmetric_Difference(a,b)
|
||||
?Symmetric_Difference(b,a)
|
||||
?Symmetric_Difference(b,b)
|
||||
Loading…
Add table
Add a link
Reference in a new issue