- (void)viewDidLoad {
[super viewDidLoad];
NSArray *arr = @[@"8", @"2", @"4", @"6"];
NSLog(@"======%d",[self isPeiBoWithArray:arr]);
}
- (BOOL)isPeiBoWithArray:(NSArray *)arr {
BOOL nm = YES;
for (int i = 0; i < arr.count - 2; i++) {
if ([arr[i] integerValue] + [arr[i + 1] integerValue] != [arr[i + 2] integerValue]) {
nm = NO;
break;
}
if (i == arr.count || [arr[i] integerValue] + [arr[i + 1] integerValue] == [arr[i + 2] integerValue]) {
nm = YES;
}
}
BOOL isP = NO;
for (int i = 0; i < arr.count; i++ ) {
isP = [self ispeiboWith:[arr[i] intValue]];
NSLog(@"数子是不是%d", isP);
if (isP == NO) {
break;
}
}
if (nm && isP) {
return YES;
}else {
return NO;
}
}
- (BOOL)ispeiboWith:(int)t {
int i = 0;
BOOL nm = YES;
for (i = 1; [self fib:i] <= t; i++) {
if ([self fib:i] == t) {
nm = YES;
}else {
nm = NO;
}
}
return nm;
}
- (int)fib:(int)n {
if (n == 1 || n == 2) {
return 1;
}else {
return [self fib:n - 1] + [self fib:n - 2];
}
}
网友评论