Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
25
Task/Man-or-boy-test/Objective-C/man-or-boy-test-1.m
Normal file
25
Task/Man-or-boy-test/Objective-C/man-or-boy-test-1.m
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
|
||||
typedef NSInteger (^IntegerBlock)(void);
|
||||
|
||||
NSInteger A (NSInteger kParam, IntegerBlock x1, IntegerBlock x2, IntegerBlock x3, IntegerBlock x4, IntegerBlock x5) {
|
||||
__block NSInteger k = kParam;
|
||||
__block __weak IntegerBlock weak_B;
|
||||
IntegerBlock B;
|
||||
weak_B = B = ^ {
|
||||
return A(--k, weak_B, x1, x2, x3, x4);
|
||||
};
|
||||
return k <= 0 ? x4() + x5() : B();
|
||||
}
|
||||
|
||||
IntegerBlock K (NSInteger n) {
|
||||
return ^{return n;};
|
||||
}
|
||||
|
||||
int main (int argc, const char * argv[]) {
|
||||
@autoreleasepool {
|
||||
NSInteger result = A(10, K(1), K(-1), K(-1), K(1), K(0));
|
||||
NSLog(@"%d\n", result);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
24
Task/Man-or-boy-test/Objective-C/man-or-boy-test-2.m
Normal file
24
Task/Man-or-boy-test/Objective-C/man-or-boy-test-2.m
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
|
||||
typedef NSInteger (^IntegerBlock)(void);
|
||||
|
||||
NSInteger A (NSInteger kParam, IntegerBlock x1, IntegerBlock x2, IntegerBlock x3, IntegerBlock x4, IntegerBlock x5) {
|
||||
__block NSInteger k = kParam;
|
||||
__block IntegerBlock B;
|
||||
B = ^ {
|
||||
return A(--k, B, x1, x2, x3, x4);
|
||||
};
|
||||
return k <= 0 ? x4() + x5() : B();
|
||||
}
|
||||
|
||||
IntegerBlock K (NSInteger n) {
|
||||
return [[^{return n;} copy] autorelease];
|
||||
}
|
||||
|
||||
int main (int argc, const char * argv[]) {
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
NSInteger result = A(10, K(1), K(-1), K(-1), K(1), K(0));
|
||||
NSLog(@"%d\n", result);
|
||||
[pool drain];
|
||||
return 0;
|
||||
}
|
||||
73
Task/Man-or-boy-test/Objective-C/man-or-boy-test-3.m
Normal file
73
Task/Man-or-boy-test/Objective-C/man-or-boy-test-3.m
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
@protocol IntegerFun <NSObject>
|
||||
-(NSInteger)call;
|
||||
@end
|
||||
|
||||
NSInteger A (NSInteger kParam, id<IntegerFun> x1, id<IntegerFun> x2, id<IntegerFun> x3, id<IntegerFun> x4, id<IntegerFun> x5);
|
||||
|
||||
@interface B_Class : NSObject <IntegerFun> {
|
||||
NSInteger *k;
|
||||
id<IntegerFun> x1, x2, x3, x4;
|
||||
}
|
||||
-(id)initWithK:(NSInteger *)k x1:(id<IntegerFun>)x1 x2:(id<IntegerFun>)x2 x3:(id<IntegerFun>)x3 x4:(id<IntegerFun>)x4;
|
||||
@end
|
||||
|
||||
@implementation B_Class
|
||||
-(id)initWithK:(NSInteger *)_k x1:(id<IntegerFun>)_x1 x2:(id<IntegerFun>)_x2 x3:(id<IntegerFun>)_x3 x4:(id<IntegerFun>)_x4 {
|
||||
if ((self = [super init])) {
|
||||
k = _k;
|
||||
x1 = [_x1 retain];
|
||||
x2 = [_x2 retain];
|
||||
x3 = [_x3 retain];
|
||||
x4 = [_x4 retain];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
-(void)dealloc {
|
||||
[x1 release];
|
||||
[x2 release];
|
||||
[x3 release];
|
||||
[x4 release];
|
||||
[super dealloc];
|
||||
}
|
||||
-(NSInteger)call {
|
||||
return A(--*k, self, x1, x2, x3, x4);
|
||||
}
|
||||
@end
|
||||
|
||||
NSInteger A (NSInteger k, id<IntegerFun> x1, id<IntegerFun> x2, id<IntegerFun> x3, id<IntegerFun> x4, id<IntegerFun> x5) {
|
||||
id<IntegerFun> B = [[[B_Class alloc] initWithK:&k x1:x1 x2:x2 x3:x3 x4:x4] autorelease];
|
||||
return k <= 0 ? [x4 call] + [x5 call] : [B call];
|
||||
}
|
||||
|
||||
@interface K : NSObject <IntegerFun> {
|
||||
NSInteger n;
|
||||
}
|
||||
-(id)initWithN:(NSInteger)n;
|
||||
@end
|
||||
|
||||
@implementation K
|
||||
-(id)initWithN:(NSInteger)_n {
|
||||
if ((self = [super init])) {
|
||||
n = _n;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
-(NSInteger)call {
|
||||
return n;
|
||||
}
|
||||
@end
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
NSInteger result = A(10,
|
||||
[[[K alloc] initWithN:1] autorelease],
|
||||
[[[K alloc] initWithN:-1] autorelease],
|
||||
[[[K alloc] initWithN:-1] autorelease],
|
||||
[[[K alloc] initWithN:1] autorelease],
|
||||
[[[K alloc] initWithN:0] autorelease]);
|
||||
NSLog(@"%ld\n", result);
|
||||
|
||||
[pool release];
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue