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.139 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.138 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.137 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.136 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.135 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.134 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.133 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.132 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.131 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.130 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.129 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.128 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.127 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.126 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.125 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.124 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.123 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.122 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.121 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.120 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m