March 2014 update
This commit is contained in:
parent
09687c4926
commit
a25938f123
1846 changed files with 21876 additions and 5203 deletions
51
Task/Set/AutoHotkey/set-1.ahk
Normal file
51
Task/Set/AutoHotkey/set-1.ahk
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
test(Set,element){
|
||||
for i, val in Set
|
||||
if (val=element)
|
||||
return true
|
||||
return false
|
||||
}
|
||||
|
||||
Union(SetA,SetB){
|
||||
SetC:=[], Temp:=[]
|
||||
for i, val in SetA
|
||||
SetC.Insert(val), Temp[val] := true
|
||||
for i, val in SetB
|
||||
if !Temp[val]
|
||||
SetC.Insert(val)
|
||||
return SetC
|
||||
}
|
||||
|
||||
intersection(SetA,SetB){
|
||||
SetC:=[], Temp:=[]
|
||||
for i, val in SetA
|
||||
Temp[val] := true
|
||||
for i, val in SetB
|
||||
if Temp[val]
|
||||
SetC.Insert(val)
|
||||
return SetC
|
||||
}
|
||||
|
||||
difference(SetA,SetB){
|
||||
SetC:=[], Temp:=[]
|
||||
for i, val in SetB
|
||||
Temp[val] := true
|
||||
for i, val in SetA
|
||||
if !Temp[val]
|
||||
SetC.Insert(val)
|
||||
return SetC
|
||||
}
|
||||
|
||||
subset(SetA,SetB){
|
||||
Temp:=[], A:=B:=0
|
||||
for i, val in SetA
|
||||
Temp[val] := true , A++
|
||||
for i, val in SetB
|
||||
if Temp[val]{
|
||||
B++
|
||||
IfEqual, A, %B%, return 1
|
||||
} return 0
|
||||
}
|
||||
|
||||
equal(SetA,SetB){
|
||||
return (SetA.MaxIndex() = SetB.MaxIndex() && subset(SetA,SetB)) ? 1: 0
|
||||
}
|
||||
42
Task/Set/AutoHotkey/set-2.ahk
Normal file
42
Task/Set/AutoHotkey/set-2.ahk
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
A:= ["apple", "cherry", "elderberry", "grape"]
|
||||
B:= ["banana", "cherry", "date", "elderberry", "fig"]
|
||||
C:= ["apple", "cherry", "elderberry", "grape", "orange"]
|
||||
D:= ["apple", "cherry", "elderberry", "grape"]
|
||||
E:= ["apple", "cherry", "elderberry"]
|
||||
M:= "banana"
|
||||
|
||||
Res =
|
||||
(
|
||||
A:= ["apple", "cherry", "elderberry", "grape"]
|
||||
B:= ["banana", "cherry", "date", "elderberry", "fig"]
|
||||
C:= ["apple", "cherry", "elderberry", "grape", "orange"]
|
||||
D:= ["apple", "cherry", "elderberry", "grape"]
|
||||
E:= ["apple", "cherry", "elderberry"]
|
||||
M:= "banana"
|
||||
|
||||
)
|
||||
|
||||
Res .= "`nM is " (test(A,M)?"":"not ") "an element of Set A"
|
||||
Res .= "`nM is " (test(B,M)?"":"not ") "an element of Set B"
|
||||
|
||||
Res .= "`nUnion(A,B) = "
|
||||
for i, val in Union(A,B)
|
||||
Res.= (A_Index=1?"`t":", ") val
|
||||
|
||||
Res .= "`nintersection(A,B) = "
|
||||
for i, val in intersection(A,B)
|
||||
Res.= (A_Index=1?"`t":", ") val
|
||||
|
||||
Res .= "`ndifference(A,B) = "
|
||||
for i, val in difference(A,B)
|
||||
Res.= (A_Index=1?"`t":", ") val
|
||||
|
||||
Res .= "`n`nA is " (subset(A,C)?"":"not ") "a subset of Set C"
|
||||
Res .= "`nA is " (subset(A,D)?"":"not ") "a subset of Set D"
|
||||
Res .= "`nA is " (subset(A,E)?"":"not ") "a subset of Set E"
|
||||
|
||||
Res .= "`n`nA is " (equal(A,C)?"":"not ") "a equal to Set C"
|
||||
Res .= "`nA is " (equal(A,D)?"":"not ") "a equal to Set D"
|
||||
Res .= "`nA is " (equal(A,E)?"":"not ") "a equal to Set E"
|
||||
|
||||
MsgBox % Res
|
||||
38
Task/Set/Dart/set.dart
Normal file
38
Task/Set/Dart/set.dart
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
void main(){
|
||||
//Set Creation
|
||||
Set A = new Set.from([1,2,3]);
|
||||
Set B = new Set.from([1,2,3,4,5]);
|
||||
Set C = new Set.from([1,2,4,5]);
|
||||
|
||||
print('Set A = $A');
|
||||
print('Set B = $B');
|
||||
print('Set C = $C');
|
||||
print('');
|
||||
//Test if element is in set
|
||||
int m = 3;
|
||||
print('m = 5');
|
||||
print('m in A = ${A.contains(m)}');
|
||||
print('m in B = ${B.contains(m)}');
|
||||
print('m in C = ${C.contains(m)}');
|
||||
print('');
|
||||
//Union of two sets
|
||||
Set AC = A.union(C);
|
||||
print('Set AC = Union of A and C = $AC');
|
||||
print('');
|
||||
//Intersection of two sets
|
||||
Set A_C = A.intersection(C);
|
||||
print('Set A_C = Intersection of A and C = $A_C');
|
||||
print('');
|
||||
//Difference of two sets
|
||||
Set A_diff_C = A.difference(C);
|
||||
print('Set A_diff_C = Difference between A and C = $A_diff_C');
|
||||
print('');
|
||||
//Test if set is subset of another set
|
||||
print('A is a subset of B = ${B.containsAll(A)}');
|
||||
print('C is a subset of B = ${B.containsAll(C)}');
|
||||
print('A is a subset of C = ${C.containsAll(A)}');
|
||||
print('');
|
||||
//Test if two sets are equal
|
||||
print('A is equal to B = ${B.containsAll(A) && A.containsAll(B)}');
|
||||
print('B is equal to AC = ${B.containsAll(AC) && AC.containsAll(B)}');
|
||||
}
|
||||
|
|
@ -1,57 +1,57 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
|
||||
int main (int argc, const char *argv[]) {
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
@autoreleasepool {
|
||||
|
||||
NSSet *s1 = [NSSet setWithObjects:@"a", @"b", @"c", @"d", @"e", nil];
|
||||
NSSet *s2 = [NSSet setWithObjects:@"b", @"c", @"d", @"e", @"f", @"h", nil];
|
||||
NSSet *s3 = [NSSet setWithObjects:@"b", @"c", @"d", nil];
|
||||
NSSet *s4 = [NSSet setWithObjects:@"b", @"c", @"d", nil];
|
||||
NSLog(@"s1: %@", s1);
|
||||
NSLog(@"s2: %@", s2);
|
||||
NSLog(@"s3: %@", s3);
|
||||
NSLog(@"s4: %@", s4);
|
||||
NSSet *s1 = [NSSet setWithObjects:@"a", @"b", @"c", @"d", @"e", nil];
|
||||
NSSet *s2 = [NSSet setWithObjects:@"b", @"c", @"d", @"e", @"f", @"h", nil];
|
||||
NSSet *s3 = [NSSet setWithObjects:@"b", @"c", @"d", nil];
|
||||
NSSet *s4 = [NSSet setWithObjects:@"b", @"c", @"d", nil];
|
||||
NSLog(@"s1: %@", s1);
|
||||
NSLog(@"s2: %@", s2);
|
||||
NSLog(@"s3: %@", s3);
|
||||
NSLog(@"s4: %@", s4);
|
||||
|
||||
// Membership
|
||||
NSLog(@"b in s1: %d", [s1 containsObject:@"b"]);
|
||||
NSLog(@"f in s1: %d", [s1 containsObject:@"f"]);
|
||||
// Membership
|
||||
NSLog(@"b in s1: %d", [s1 containsObject:@"b"]);
|
||||
NSLog(@"f in s1: %d", [s1 containsObject:@"f"]);
|
||||
|
||||
// Union
|
||||
NSMutableSet *s12 = [NSMutableSet setWithSet:s1];
|
||||
[s12 unionSet:s2];
|
||||
NSLog(@"s1 union s2: %@", s12);
|
||||
// Union
|
||||
NSMutableSet *s12 = [NSMutableSet setWithSet:s1];
|
||||
[s12 unionSet:s2];
|
||||
NSLog(@"s1 union s2: %@", s12);
|
||||
|
||||
// Intersection
|
||||
NSMutableSet *s1i2 = [NSMutableSet setWithSet:s1];
|
||||
[s1i2 intersectSet:s2];
|
||||
NSLog(@"s1 intersect s2: %@", s1i2);
|
||||
// Intersection
|
||||
NSMutableSet *s1i2 = [NSMutableSet setWithSet:s1];
|
||||
[s1i2 intersectSet:s2];
|
||||
NSLog(@"s1 intersect s2: %@", s1i2);
|
||||
|
||||
// Difference
|
||||
NSMutableSet *s1_2 = [NSMutableSet setWithSet:s1];
|
||||
[s1_2 minusSet:s2];
|
||||
NSLog(@"s1 - s2: %@", s1_2);
|
||||
// Difference
|
||||
NSMutableSet *s1_2 = [NSMutableSet setWithSet:s1];
|
||||
[s1_2 minusSet:s2];
|
||||
NSLog(@"s1 - s2: %@", s1_2);
|
||||
|
||||
// Subset of
|
||||
NSLog(@"s3 subset of s1: %d", [s3 isSubsetOfSet:s1]);
|
||||
// Subset of
|
||||
NSLog(@"s3 subset of s1: %d", [s3 isSubsetOfSet:s1]);
|
||||
|
||||
// Equality
|
||||
NSLog(@"s3 = s4: %d", [s3 isEqualToSet:s4]);
|
||||
// Equality
|
||||
NSLog(@"s3 = s4: %d", [s3 isEqualToSet:s4]);
|
||||
|
||||
// Cardinality
|
||||
NSLog(@"size of s1: %lu", [s1 count]);
|
||||
// Cardinality
|
||||
NSLog(@"size of s1: %lu", [s1 count]);
|
||||
|
||||
// Has intersection (not disjoint)
|
||||
NSLog(@"does s1 intersect s2? %d", [s1 intersectsSet:s2]);
|
||||
// Has intersection (not disjoint)
|
||||
NSLog(@"does s1 intersect s2? %d", [s1 intersectsSet:s2]);
|
||||
|
||||
// Adding and removing elements from a mutable set
|
||||
NSMutableSet *mut_s1 = [NSMutableSet setWithSet:s1];
|
||||
[mut_s1 addObject:@"g"];
|
||||
NSLog(@"mut_s1 after adding g: %@", mut_s1);
|
||||
[mut_s1 addObject:@"b"];
|
||||
NSLog(@"mut_s1 after adding b again: %@", mut_s1);
|
||||
[mut_s1 removeObject:@"c"];
|
||||
NSLog(@"mut_s1 after removing c: %@", mut_s1);
|
||||
// Adding and removing elements from a mutable set
|
||||
NSMutableSet *mut_s1 = [NSMutableSet setWithSet:s1];
|
||||
[mut_s1 addObject:@"g"];
|
||||
NSLog(@"mut_s1 after adding g: %@", mut_s1);
|
||||
[mut_s1 addObject:@"b"];
|
||||
NSLog(@"mut_s1 after adding b again: %@", mut_s1);
|
||||
[mut_s1 removeObject:@"c"];
|
||||
NSLog(@"mut_s1 after removing c: %@", mut_s1);
|
||||
|
||||
[pool release];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue