langs a-z

This commit is contained in:
Ingy döt Net 2013-04-10 22:43:41 -07:00
parent db842d013d
commit d066446780
11389 changed files with 98361 additions and 1020 deletions

View file

@ -0,0 +1,35 @@
#import <Foundation/Foundation.h>
typedef NSArray *(^SOfN)(id);
SOfN s_of_n_creator(int n) {
NSMutableArray *sample = [NSMutableArray arrayWithCapacity:n];
__block int i = 0;
return [[^(id item) {
i++;
if (i <= n) {
[sample addObject:item];
} else if (rand() % i < n) {
[sample replaceObjectAtIndex:rand() % n withObject:item];
}
return sample;
} copy] autorelease];
}
int main(int argc, const char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSCountedSet *bin = [[NSCountedSet alloc] init];
for (int trial = 0; trial < 100000; trial++) {
SOfN s_of_n = s_of_n_creator(3);
NSArray *sample;
for (int i = 0; i < 10; i++)
sample = s_of_n([NSNumber numberWithInt:i]);
[bin addObjectsFromArray:sample];
}
NSLog(@"%@", bin);
[bin release];
[pool release];
return 0;
}