March 2014 update

This commit is contained in:
Ingy döt Net 2014-04-02 16:56:35 +00:00
parent 09687c4926
commit a25938f123
1846 changed files with 21876 additions and 5203 deletions

View file

@ -10,7 +10,7 @@ BigInt A(in int k, in int x1, in int x2, in int x3,
static immutable t = [0, 0, 0, 1, 2, 3];
return t[k].BigInt;
}
alias memoize!c1_ c1;
alias c1 = memoize!c1_;
static BigInt c2_(in int k) {
if (k > 5)
@ -18,7 +18,7 @@ BigInt A(in int k, in int x1, in int x2, in int x3,
static immutable t = [0, 0, 1, 1, 1, 2];
return t[k].BigInt;
}
alias memoize!c2_ c2;
alias c2 = memoize!c2_;
static BigInt c3_(in int k) {
if (k > 5)
@ -26,7 +26,7 @@ BigInt A(in int k, in int x1, in int x2, in int x3,
static immutable t = [0, 1, 1, 0, 0, 1];
return t[k].BigInt;
}
alias memoize!c3_ c3;
alias c3 = memoize!c3_;
static BigInt c4_(in int k) {
if (k > 5)
@ -34,7 +34,7 @@ BigInt A(in int k, in int x1, in int x2, in int x3,
static immutable t = [1, 1, 0, 0, 0, 0];
return t[k].BigInt;
}
alias memoize!c4_ c4;
alias c4 = memoize!c4_;
static int c5(in int k) pure nothrow {
return !!k;
@ -48,6 +48,7 @@ BigInt A(in int k, in int x1, in int x2, in int x3,
void main() {
import std.stdio, std.conv, std.range;
foreach (immutable i; 0 .. 40)
writeln(i, " ", A(i, 1, -1, -1, 1, 0));

View file

@ -1,25 +1,25 @@
#import <Foundation/Foundation.h>
typedef NSInteger (^IntegerBlock)();
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; // due to a GCC bug, we have to initialize on a separate line
B = ^ {
return A(--k, B, x1, x2, x3, x4);
__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) {
IntegerBlock result = ^{return n;};
return [[result copy] autorelease];
return ^{return n;};
}
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];
@autoreleasepool {
NSInteger result = A(10, K(1), K(-1), K(-1), K(1), K(0));
NSLog(@"%d\n", result);
}
return 0;
}

View file

@ -1,73 +1,24 @@
@protocol IntegerFun <NSObject>
-(NSInteger)call;
@end
#import <Foundation/Foundation.h>
NSInteger A (NSInteger kParam, id<IntegerFun> x1, id<IntegerFun> x2, id<IntegerFun> x3, id<IntegerFun> x4, id<IntegerFun> x5);
typedef NSInteger (^IntegerBlock)(void);
@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];
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();
}
@interface K : NSObject <IntegerFun> {
NSInteger n;
IntegerBlock K (NSInteger n) {
return [[^{return n;} copy] autorelease];
}
-(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;
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;
}

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