Time for an 2014 update…

This commit is contained in:
Ingy döt Net 2014-01-17 05:32:22 +00:00
parent 372c577f83
commit 09687c4926
2520 changed files with 34227 additions and 7318 deletions

View file

@ -11,4 +11,4 @@ symmetric-difference A B:
b
set{
. symmetric-difference setA setB
!. symmetric-difference setA setB

View file

@ -0,0 +1,29 @@
function Difference(A,B)
{
var a = A.length, b = B.length, c = 0, C = [];
for (var i = 0; i < a; i++)
{ var j = 0, k = 0;
while (j < b && B[j] !== A[i]) j++;
while (k < c && C[k] !== A[i]) k++;
if (j == b && k == c) C[c++] = A[i];
}
return C;
}
function SymmetricDifference(A,B)
{
var D1 = Difference(A,B), D2 = Difference(B,A),
a = D1.length, b = D2.length;
for (var i = 0; i < b; i++) D1[a++] = D2[i];
return D1;
}
/* Example
A = ['John', 'Serena', 'Bob', 'Mary', 'Serena'];
B = ['Jim', 'Mary', 'John', 'Jim', 'Bob'];
Difference(A,B); // 'Serena'
Difference(B,A); // 'Jim'
SymmetricDifference(A,B); // 'Serena','Jim'
*/

View file

@ -0,0 +1,43 @@
/*REXX pgm finds symmetric difference and symm. AND (between two lists).*/
a.=0 /*falsify the booleans*/
a= '["John", "Serena", "Bob", "Mary", "Serena"]' /*note the duplicate. */
b= '["Jim", "Mary", "John", "Jim", "Bob"]' /* " " " */
a.1=a; say 'list A =' a /*assign and display. */
a.2=b; say 'list B =' b /* " " " */
SD= ; SA= /*Sym. Diff; Sym And.*/
SD.=0; SA.=0 /*falsify SD & SA bool*/
/*══════════════════════════════════════════════════parse the two lists.*/
do k=1 for 2 /*process both lists (stemmed array).*/
a.k=strip(strip(a.k,,"["),,']') /*strip leading and trailing brackets*/
do j=1 until a.k='' /*parse names [they may have blanks]*/
a.k=strip(a.k,,',') /*strip comma (if any)*/
parse var a.k '"' _ '"' a.k /*get the list's name.*/
a.k.j=_ /*store the list name.*/
a.k._=1 /*make a boolean val. */
end /*j*/
a.k.0=j-1 /*number of list names*/
end /*k*/
/*══════════════════════════════════════════════════find symmetric DIFF.*/
do k=1 for 2 /*process both lists. */
ko=word(2 1,k) /*point to other list.*/
do j=1 for a.k.0; _=a.k.j /*process list names. */
if \a.ko._ & \SD._ then do /*if not in both··· */
SD=SD '"'_'",' /*add to sym diff list*/
SD._=1 /*"trueify" a boolean.*/
end
end /*j*/
end /*k*/
SD= "["strip(strip(SD),'T',",")']' /*clean up and [ ] it*/
say; say 'symmetric difference =' SD /*show symmetric DIFF.*/
/*══════════════════════════════════════════════════find symmetric AND. */
do j=1 for a.1.0; _=a.1.j /*process A list names*/
if a.1._ & a.2._ & \SA._ then do /*if common to both···*/
SA=SA '"'_'",' /*add to symmetric AND*/
SA._=1 /*"trueify" a boolean.*/
end
end /*j*/
SA="["strip(strip(SA),'T',",")']' /*clean up and [ ] it*/
say; say ' symmetric AND =' SA /*show symmetric DIFF.*/
/*stick a fork in it, we're done.*/

View file

@ -0,0 +1,7 @@
/*REXX pgm finds symmetric difference and symm. AND (between two lists).*/
a.=0 /*falsify the booleans*/
a= '["Zahn", "Yi", "Stands with a Fist", "", "Hungry Wolf", "Yi"]'
b= '["Draag Ng [Jr.]", "Patzy", "Zahn", "Yi", "Robert the Bruce"]'

View file

@ -0,0 +1,25 @@
/* REXX ---------------------------------------------------------------
* 14.12.2013 Walter Pachl a short solution
* 16.12.2013 fix duplicate element problem in input
* 16.12.2013 added duplicate to t.
* Handles only sets the elements of which do not contain blanks
*--------------------------------------------------------------------*/
s='John Bob Mary Serena'
t='Jim Mary John Bob Jim '
Say difference(s,t)
Exit
difference:
Parse Arg a,b
res=''
Do i=1 To words(a)
If wordpos(word(a,i),b)=0 Then
Call out word(a,i)
End
Do i=1 To words(b)
If wordpos(word(b,i),a)=0 Then
Call out word(b,i)
End
Return strip(res)
out: parse Arg e
If wordpos(e,res)=0 Then res=res e
Return

View file

@ -1,46 +0,0 @@
/*REXX program to find the symmetric difference (between two strings). */
a.=0 /*falisify all the a.k._ booleans. */
a= '["John", "Serena", "Bob", "Mary", "Serena"]'
b= '["Jim", "Mary", "John", "Jim", "Bob"]'
a.1=a; say 'list A =' a
a.2=b; say 'list B =' b
SD= ; SA= /*Sym. Diff, Sym "And"*/
SD.=0; SA.=0 /*falsify SD & SA bool*/
do k=1 for 2 /*process both lists (stemmed array).*/
a.k=strip(strip(a.k,,"["),,']') /*strip leading and trailing brackets*/
do j=1 until a.k='' /*parse names, they may have blanks. */
a.k=strip(a.k,,',') /*strip comma (if any)*/
parse var a.k '"' _ '"' a.k /*get the list's name.*/
a.k.j=_ /*store the list name.*/
a.k._=1 /*make a boolean val. */
end /*j*/
a.k.0=j-1 /*number of list names*/
end /*k*/
/*══════════════════════════════════════════════════find symmetric diff.*/
do k=1 for 2 /*process both lists. */
ko=word(2 1,k) /*point to other list.*/
do j=1 for a.k.0; _=a.k.j /*process list names. */
if \a.ko._ & \SD._ then do /*if not in both... */
SD=SD '"'_'",' /*add to sym diff list*/
SD._=1 /*"trueify" a boolean.*/
end
end /*j*/
end /*k*/
SD= "["strip(space(SD),'T',",")']' /*clean up and bracket*/
say; say 'symmetric difference =' SD /*show and tell the SD*/
/*══════════════════════════════════════════════════find symmetric AND. */
do j=1 for a.1.0; _=a.1.j /*process A list names*/
if a.1._ & a.2._ & \SA._ then do /*if common to both...*/
SA=SA '"'_'",' /*add to sym AND list.*/
SA._=1 /*"trueify" a boolean.*/
end
end /*j*/
SA="["strip(space(SA),'T',",")']' /*clean up and bracket*/
say; say ' symmetric AND =' SA /*show and tell the SA*/
/*stick a fork in it, we're done.*/