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.180 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.179 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.178 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.177 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.176 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.175 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.174 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.173 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.172 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.171 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.170 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.169 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.167 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.166 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.165 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.164 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.163 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.162 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.161 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.160 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m