Sync
This commit is contained in:
parent
6f050a029e
commit
776bba907c
3887 changed files with 59894 additions and 7280 deletions
31
Task/Symmetric-difference/AWK/symmetric-difference.awk
Normal file
31
Task/Symmetric-difference/AWK/symmetric-difference.awk
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# syntax: GAWK -f SYMMETRIC_DIFFERENCE.AWK
|
||||
BEGIN {
|
||||
load("John,Bob,Mary,Serena",A)
|
||||
load("Jim,Mary,John,Bob",B)
|
||||
show("A \\ B",A,B)
|
||||
show("B \\ A",B,A)
|
||||
printf("symmetric difference: ")
|
||||
for (i in C) {
|
||||
if (!(i in A && i in B)) {
|
||||
printf("%s ",i)
|
||||
}
|
||||
}
|
||||
printf("\n")
|
||||
exit(0)
|
||||
}
|
||||
function load(str,arr, i,n,temp) {
|
||||
n = split(str,temp,",")
|
||||
for (i=1; i<=n; i++) {
|
||||
arr[temp[i]]
|
||||
C[temp[i]]
|
||||
}
|
||||
}
|
||||
function show(str,a,b, i) {
|
||||
printf("%s: ",str)
|
||||
for (i in a) {
|
||||
if (!(i in b)) {
|
||||
printf("%s ",i)
|
||||
}
|
||||
}
|
||||
printf("\n")
|
||||
}
|
||||
|
|
@ -3,22 +3,23 @@ import std.stdio, std.algorithm, std.array;
|
|||
struct Set(T) {
|
||||
immutable T[] items;
|
||||
|
||||
Set opSub(in Set other) const /*pure nothrow*/ {
|
||||
return Set(array(filter!(a=> !canFind(other.items,a))(items)));
|
||||
Set opSub(in Set other) const pure nothrow {
|
||||
return items.filter!(x => !other.items.canFind(x)).array.Set;
|
||||
}
|
||||
|
||||
Set opAdd(in Set other) const /*pure nothrow*/ {
|
||||
Set opAdd(in Set other) const pure nothrow {
|
||||
return Set(this.items ~ (other - this).items);
|
||||
}
|
||||
}
|
||||
|
||||
Set!T symmetricDifference(T)(in Set!T left, in Set!T right) {
|
||||
Set!T symmetricDifference(T)(in Set!T left, in Set!T right)
|
||||
pure nothrow {
|
||||
return (left - right) + (right - left);
|
||||
}
|
||||
|
||||
void main() {
|
||||
immutable A = Set!string(["John", "Bob", "Mary", "Serena"]);
|
||||
immutable B = Set!string(["Jim", "Mary", "John", "Bob"]);
|
||||
immutable A = ["John", "Bob", "Mary", "Serena"].Set!string;
|
||||
immutable B = ["Jim", "Mary", "John", "Bob"].Set!string;
|
||||
|
||||
writeln(" A\\B: ", (A - B).items);
|
||||
writeln(" B\\A: ", (B - A).items);
|
||||
|
|
|
|||
14
Task/Symmetric-difference/Deja-Vu/symmetric-difference.djv
Normal file
14
Task/Symmetric-difference/Deja-Vu/symmetric-difference.djv
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
set :setA set{ :John :Bob :Mary :Serena }
|
||||
set :setB set{ :Jim :Mary :John :Bob }
|
||||
|
||||
symmetric-difference A B:
|
||||
}
|
||||
for a in keys A:
|
||||
if not has B a:
|
||||
a
|
||||
for b in keys B:
|
||||
if not has A b:
|
||||
b
|
||||
set{
|
||||
|
||||
. symmetric-difference setA setB
|
||||
11
Task/Symmetric-difference/Erlang/symmetric-difference.erl
Normal file
11
Task/Symmetric-difference/Erlang/symmetric-difference.erl
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
%% Implemented by Arjun Sunel
|
||||
-module(symdiff).
|
||||
-export([main/0]).
|
||||
|
||||
main() ->
|
||||
SetA = sets:from_list(["John","Bob","Mary","Serena"]),
|
||||
SetB = sets:from_list(["Jim","Mary","John","Bob"]),
|
||||
AUnionB = sets:union(SetA,SetB),
|
||||
AIntersectionB = sets:intersection(SetA,SetB),
|
||||
SymmDiffAB = sets:subtract(AUnionB,AIntersectionB),
|
||||
sets:to_list(SymmDiffAB).
|
||||
21
Task/Symmetric-difference/PL-I/symmetric-difference.pli
Normal file
21
Task/Symmetric-difference/PL-I/symmetric-difference.pli
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/* PL/I ***************************************************************
|
||||
* 17.08.2013 Walter Pachl
|
||||
**********************************************************************/
|
||||
*process source attributes xref;
|
||||
sd: Proc Options(main);
|
||||
Dcl a(4) Char(20) Var Init('John','Bob','Mary','Serena');
|
||||
Dcl b(4) Char(20) Var Init('Jim','Mary','John','Bob');
|
||||
Call match(a,b);
|
||||
Call match(b,a);
|
||||
match: Proc(x,y);
|
||||
Dcl (x(*),y(*)) Char(*) Var;
|
||||
Dcl (i,j) Bin Fixed(31);
|
||||
Do i=1 To hbound(x);
|
||||
Do j=1 To hbound(y);
|
||||
If x(i)=y(j) Then Leave;
|
||||
End;
|
||||
If j>hbound(y) Then
|
||||
Put Edit(x(i))(Skip,a);
|
||||
End;
|
||||
End;
|
||||
End;
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
use Set;
|
||||
my $A = set <John Serena Bob Mary Serena>;
|
||||
my $B = set <Jim Mary John Jim Bob>;
|
||||
|
||||
|
|
|
|||
20
Task/Symmetric-difference/Run-BASIC/symmetric-difference.run
Normal file
20
Task/Symmetric-difference/Run-BASIC/symmetric-difference.run
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
setA$ = "John,Bob,Mary,Serena"
|
||||
setB$ = "Jim,Mary,John,Bob"
|
||||
|
||||
x$ = b$(setA$,setB$)
|
||||
print word$(x$,1,",")
|
||||
c$ = c$ + x$
|
||||
|
||||
x$ = b$(setB$,setA$)
|
||||
print word$(x$,1,",")
|
||||
print c$;x$
|
||||
end
|
||||
function b$(a$,b$)
|
||||
i = 1
|
||||
while word$(a$,i,",") <> ""
|
||||
a1$ = word$(a$,i,",")
|
||||
j = instr(b$,a1$)
|
||||
if j <> 0 then b$ = left$(b$,j-1) + mid$(b$,j+len(a1$)+1)
|
||||
i = i + 1
|
||||
wend
|
||||
end function
|
||||
Loading…
Add table
Add a link
Reference in a new issue