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.159 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.158 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.157 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.156 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.155 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.154 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.153 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.152 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.151 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.150 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.149 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.148 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.147 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.146 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.145 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.144 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.143 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.142 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.141 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m
trackler-2.2.1.140 tracks/objective-c/exercises/collatz-conjecture/CollatzConjectureExample.m