Sha256: 8a3ddbd8600e8892480a9b9a78899a58ff20ea5d0e7be30cd86fa6ccba23b303

Contents?: true

Size: 457 Bytes

Versions: 78

Compression:

Stored size: 457 Bytes

Contents

#import "CollatzConjectureExample.h"

@implementation CollatzConjecture

+ (NSInteger)stepsForNumber:(NSInteger)number {
    if (number <= 0) {
        return NSNotFound;
    }
    
    NSInteger current = number;
    NSInteger steps = 0;
    
    while (current > 1) {
        steps++;
        
        if (current % 2 == 0) {
            current /= 2;
        } else {
            current = current * 3 + 1;
        }
    }
    
    return steps;
}

@end

Version data entries

78 entries across 78 versions & 1 rubygems

Version Path
trackler-2.2.1.119 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.118 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.117 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.116 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.115 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.114 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.113 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.111 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.110 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.109 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.108 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.107 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.106 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.105 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.104 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.103 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.102 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.101 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m