Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View 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);

View 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 ) );
]

View 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

View 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

View file

@ -0,0 +1,3 @@
var a = ["John", "Serena", "Bob", "Mary", "Serena"];
var b = ["Jim", "Mary", "John", "Jim", "Bob"];
a ^ b -> unique.dump.say;

View file

@ -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

View 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));

View file

@ -0,0 +1,2 @@
symmetric_difference( [1,2,1,2]; [2,3] )
[1,3]