Sha256: 1c7d7544eedc4bdaf0bf2628c36ff2892a57225bebe9190bc3125166d2fef0da

Contents?: true

Size: 529 Bytes

Versions: 132

Compression:

Stored size: 529 Bytes

Contents

#import "NthPrimeExample.h"
@implementation NthPrime : NSObject

+(int)primeNum:(int)primeNum {
	if (primeNum == 0) {
		return 0;
	}
	int currentPrime = 0;
	int i = 0;
	while (currentPrime <= primeNum) {
		i += 1;
		if ([self isPrime:i]){
			currentPrime += 1;
		}
	}
	return i;
}
+(BOOL)isPrime:(int)n {
	if (n == 2 || n == 3) {
		return YES;
	}
	
	if (n % 2 == 0 || n % 3 == 0) {
		return NO;
	}

	int i = 5;
	int w = 2;
	while (i * i <= n) {
		if (n % i == 0) {
			return NO;
		}
		i += w;
		w = 6 - w;
	}
	return YES;
}

@end

Version data entries

132 entries across 132 versions & 1 rubygems

Version Path
trackler-2.2.1.58 tracks/objective-c/exercises/nth-prime/NthPrimeExample.m
trackler-2.2.1.57 tracks/objective-c/exercises/nth-prime/NthPrimeExample.m
trackler-2.2.1.56 tracks/objective-c/exercises/nth-prime/NthPrimeExample.m
trackler-2.2.1.55 tracks/objective-c/exercises/nth-prime/NthPrimeExample.m
trackler-2.2.1.54 tracks/objective-c/exercises/nth-prime/NthPrimeExample.m
trackler-2.2.1.53 tracks/objective-c/exercises/nth-prime/NthPrimeExample.m
trackler-2.2.1.52 tracks/objective-c/exercises/nth-prime/NthPrimeExample.m
trackler-2.2.1.51 tracks/objective-c/exercises/nth-prime/NthPrimeExample.m
trackler-2.2.1.50 tracks/objective-c/exercises/nth-prime/NthPrimeExample.m
trackler-2.2.1.49 tracks/objective-c/exercises/nth-prime/NthPrimeExample.m
trackler-2.2.1.48 tracks/objective-c/exercises/nth-prime/NthPrimeExample.m
trackler-2.2.1.47 tracks/objective-c/exercises/nth-prime/NthPrimeExample.m