Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
28
Task/Symmetric-difference/Apex/symmetric-difference.apex
Normal file
28
Task/Symmetric-difference/Apex/symmetric-difference.apex
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
Set<String> setA = new Set<String>{'John', 'Bob', 'Mary', 'Serena'};
|
||||
Set<String> setB = new Set<String>{'Jim', 'Mary', 'John', 'Bob'};
|
||||
|
||||
// Option 1
|
||||
Set<String> notInSetA = setB.clone();
|
||||
notInSetA.removeAll(setA);
|
||||
|
||||
Set<String> notInSetB = setA.clone();
|
||||
notInSetB.removeAll(setB);
|
||||
|
||||
Set<String> symmetricDifference = new Set<String>();
|
||||
symmetricDifference.addAll(notInSetA);
|
||||
symmetricDifference.addAll(notInSetB);
|
||||
|
||||
// Option 2
|
||||
Set<String> union = setA.clone();
|
||||
union.addAll(setB);
|
||||
|
||||
Set<String> intersection = setA.clone();
|
||||
intersection.retainAll(setB);
|
||||
|
||||
Set<String> symmetricDifference2 = union.clone();
|
||||
symmetricDifference2.removeAll(intersection);
|
||||
|
||||
System.debug('Not in set A: ' + notInSetA);
|
||||
System.debug('Not in set B: ' + notInSetB);
|
||||
System.debug('Symmetric Difference: ' + symmetricDifference);
|
||||
System.debug('Symmetric Difference 2: ' + symmetricDifference2);
|
||||
24
Task/Symmetric-difference/Lasso/symmetric-difference.lasso
Normal file
24
Task/Symmetric-difference/Lasso/symmetric-difference.lasso
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
[
|
||||
var(
|
||||
'a' = array(
|
||||
'John'
|
||||
,'Bob'
|
||||
,'Mary'
|
||||
,'Serena'
|
||||
)
|
||||
|
||||
,'b' = array
|
||||
|
||||
);
|
||||
|
||||
$b->insert( 'Jim' ); // Alternate method of populating array
|
||||
$b->insert( 'Mary' );
|
||||
$b->insert( 'John' );
|
||||
$b->insert( 'Bob' );
|
||||
|
||||
$a->sort( true ); // arrays must be sorted (true = ascending) for difference to work
|
||||
$b->sort( true );
|
||||
|
||||
$a->difference( $b )->union( $b->difference( $a ) );
|
||||
|
||||
]
|
||||
7
Task/Symmetric-difference/Nim/symmetric-difference.nim
Normal file
7
Task/Symmetric-difference/Nim/symmetric-difference.nim
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import sets
|
||||
|
||||
var setA = ["John", "Bob", "Mary", "Serena"].toSet
|
||||
var setB = ["Jim", "Mary", "John", "Bob"].toSet
|
||||
echo setA -+- setB # Symmetric difference
|
||||
echo setA - setB # Difference
|
||||
echo setB - setA # Difference
|
||||
29
Task/Symmetric-difference/Ring/symmetric-difference.ring
Normal file
29
Task/Symmetric-difference/Ring/symmetric-difference.ring
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
alist = []
|
||||
blist = []
|
||||
alist = ["john", "bob", "mary", "serena"]
|
||||
blist = ["jim", "mary", "john", "bob"]
|
||||
|
||||
alist2 = []
|
||||
for i = 1 to len(alist)
|
||||
flag = 0
|
||||
for j = 1 to len(blist)
|
||||
if alist[i] = blist[j] flag = 1 ok
|
||||
next
|
||||
if (flag = 0) add(alist2, alist[i]) ok
|
||||
next
|
||||
|
||||
blist2 = []
|
||||
for j = 1 to len(alist)
|
||||
flag = 0
|
||||
for i = 1 to len(blist)
|
||||
if alist[i] = blist[j] flag = 1 ok
|
||||
next
|
||||
if (flag = 0) add(blist2, blist[j]) ok
|
||||
next
|
||||
see "a xor b :" see nl
|
||||
see alist2
|
||||
see blist2 see nl
|
||||
see "a-b :" see nl
|
||||
see alist2 see nl
|
||||
see "b-a :" see nl
|
||||
see blist2 see nl
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
var a = ["John", "Serena", "Bob", "Mary", "Serena"];
|
||||
var b = ["Jim", "Mary", "John", "Jim", "Bob"];
|
||||
a ^ b -> unique.dump.say;
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
let setA : Set<String> = ["John", "Bob", "Mary", "Serena"]
|
||||
let setB : Set<String> = ["Jim", "Mary", "John", "Bob"]
|
||||
println(setA.exclusiveOr(setB)) // symmetric difference of A and B
|
||||
println(setA.subtract(setB)) // elements in A that are not in B
|
||||
10
Task/Symmetric-difference/jq/symmetric-difference-1.jq
Normal file
10
Task/Symmetric-difference/jq/symmetric-difference-1.jq
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# The following implementation of intersection (but not symmetric_difference) assumes that the
|
||||
# elements of a (and of b) are unique and do not include null:
|
||||
def intersection(a; b):
|
||||
reduce ((a + b) | sort)[] as $i
|
||||
([null, []]; if .[0] == $i then [null, .[1] + [$i]] else [$i, .[1]] end)
|
||||
| .[1] ;
|
||||
|
||||
def symmetric_difference(a;b):
|
||||
(a|unique) as $a | (b|unique) as $b
|
||||
| (($a + $b) | unique) - (intersection($a;$b));
|
||||
2
Task/Symmetric-difference/jq/symmetric-difference-2.jq
Normal file
2
Task/Symmetric-difference/jq/symmetric-difference-2.jq
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
symmetric_difference( [1,2,1,2]; [2,3] )
|
||||
[1,3]
|
||||
Loading…
Add table
Add a link
Reference in a new issue