Collatz 추측을 사용하여 수학 공정 프로젝트에서 작업하고 있는데, 내가 어딘가에서 엉망이되었음을 발견했지만 here on wikipeadia을 찾을 수있는 것처럼 역 그래프를 만들고 싶습니다. 내 코드 및 모든 역방향 값을 표시하지 않습니다 (예 : 배열에서 하나의 홀수 값을 찾은 다음 동일한 값 * 2을 표시하지만지나 가지 않습니다).Objective c, reverse Collatz NSArrays를 디버그하는 데 도움이됩니다.
#import "numberCreator.h"
@implementation numberCreator
@synthesize levels, nextX, nextY, numbers;
- (id)init
{
self = [super init];
if (self) {
numbers = [[NSMutableArray alloc]initWithCapacity:1000];//gives the array an estamated cap.
currentLevel = [[NSMutableArray alloc]initWithCapacity:25];
nextLevel = [[NSMutableArray alloc]initWithCapacity:25];
checkNumbers = [[NSMutableSet alloc]init];
}
return self;
}
//Creates all of the needed numbers in the reverce Collatz Web
- (void) create{
[currentLevel addObject:[NSNumber numberWithInt:1]];
[numbers addObject:[NSNumber numberWithInt:1]];
[numbers addObject:[NSNumber numberWithInt:0]];
[numbers addObject:[NSNumber numberWithInt:0]];
[checkNumbers addObject:[NSNumber numberWithInt:1]];
for(int x; x < levels; x++){
for(int y; y < [currentLevel count]; y++){
if([checkNumbers containsObject:[NSNumber numberWithInt:[[currentLevel objectAtIndex:y]floatValue]*2]]){}
else{
[checkNumbers addObject:[NSNumber numberWithInt:[[currentLevel objectAtIndex:y]intValue]*2]];
[numbers addObject:[NSNumber numberWithInt:[[currentLevel objectAtIndex:y]intValue]*2]];
[numbers addObject:[NSNumber numberWithInt:[[currentLevel objectAtIndex:y]intValue]]];//The array is set like Number, Parent, level
[numbers addObject:[NSNumber numberWithInt:x+1]];
[nextLevel addObject:[NSNumber numberWithInt:[[currentLevel objectAtIndex:y]intValue]*2]];
if((y-1)/3%2==1){
if([checkNumbers containsObject:[NSNumber numberWithInt:([[currentLevel objectAtIndex:y]floatValue]-1)/3]]){}
else{
[checkNumbers addObject:[NSNumber numberWithInt:([[currentLevel objectAtIndex:y]intValue]-1)/3]];
[numbers addObject:[NSNumber numberWithInt:([[currentLevel objectAtIndex:y]intValue]-1)/3]];
[numbers addObject:[NSNumber numberWithInt:[[currentLevel objectAtIndex:y]intValue]]];
[numbers addObject:[NSNumber numberWithInt:x+1]];
[nextLevel addObject:[NSNumber numberWithInt:[[currentLevel objectAtIndex:y]intValue]*2]];
}
}else{}
}
}
[currentLevel removeAllObjects];
for(int y; y < [nextLevel count]; y++){
[currentLevel addObject:[nextLevel objectAtIndex:y]];
}
[nextLevel removeAllObjects];
}
for(int x; x < [numbers count]; x++){
NSLog(@"%i", [[numbers objectAtIndex:x]intValue]);
}
}
@end
게시물 본문에 관련 코드를 넣으십시오. 그래서 모든 질문은 자체적으로 포함되어야합니다. pastebin이 해당 페이지를 삭제하면 귀하의 질문은 향후 독자에게 쓸모 없게됩니다. –