Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6960179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:22:07+00:00 2026-05-27T15:22:07+00:00

I am working on a math fair project using the Collatz conjecture, I am

  • 0

I am working on a math fair project using the Collatz conjecture, I am wanting to make a reverse graph as you can find here on wikipeadia although I have found that I have messed up somewhere in my code and it doesn’t show all of the reverse values (ex it will find one odd value from an array then that same value *2 but it won’t go past that).

    #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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:22:08+00:00Added an answer on May 27, 2026 at 3:22 pm

    Because, you work only with integer, using a NSMutableIndexSet would be much more efficient.

    #import "NumberCreator.h"
    
    @implementation NumberCreator
    @synthesize levels, numbers;
    
    - (id)init
    {
        if ( !(self = [super init] ) )
            return nil;
    
        numbers = [NSMutableIndexSet new];
        return self;
    }
    
    - (void)create
    {
        [numbers removeAllIndexes];
        [numbers addIndex:1];
    
        NSMutableIndexSet *nextLevel = [NSMutableIndexSet indexSet];
        NSMutableIndexSet *currentLevel = [NSMutableIndexSet indexSetWithIndex:1];
    
        for (int i = 0; i < levels; i++ )
        {
            [currentLevel enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
    
                if ( ! [numbers containsIndex:idx * 2] )
                    [nextLevel addIndex:idx * 2];
    
                if ( idx % 6 == 4 && ! [numbers containsIndex:(idx - 1) / 3] )
                    [nextLevel addIndex:(idx - 1) / 3];
            }];
    
            [numbers addIndexes:nextLevel];
            [currentLevel removeAllIndexes];
            [currentLevel addIndexes:nextLevel];
            [nextLevel removeAllIndexes];
        }
    
        [numbers enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
            NSLog(@"%i", idx);
        }];
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was working on a project today, and found myself using Math.Max in several
Working in Eclipse on a Dynamic Web Project (using Tomcat (v5.5) as the app
I am working on a math expression parser using regular expressions and I am
Here's what I have working: 3 textfields that are cloned with a math function
I'm working in a language that can only do binary math on 16-bit numbers
I'm working with large numbers that I can't have rounded off. Using Lua's standard
I am working on a project that needs vector math and complex numbers. I
This is fairly 'math-y' but I'm posting here because it's a Project Euler problem,
As per my question on Math Stackexchange: I am working on a project for
Working on a project at the moment and we have to implement soft deletion

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.