Sha256: 686c28b217080322de734bec19f9ddc613b8b475039084add474ea92bea8f4bf
Contents?: true
Size: 1.26 KB
Versions: 396
Compression:
Stored size: 1.26 KB
Contents
#import <Foundation/Foundation.h> #import "HammingExample.h" @interface Hamming () @property (nonatomic,strong,readwrite) NSString *firstStrand; @property (nonatomic,strong,readwrite) NSString *secondStrand; @end @implementation Hamming + (NSUInteger)compute:(NSString *)firstStrand against:(NSString *)secondStrand { Hamming *hamming = [[self alloc] initWithFirstStrand:firstStrand andSecondStrand:secondStrand]; return [hamming distance]; } - (instancetype)initWithFirstStrand:(NSString *)firstStrand andSecondStrand:(NSString *)secondStrand { self = [super init]; if (self) { self.firstStrand = firstStrand; self.secondStrand = secondStrand; } return self; } - (NSUInteger)distance { NSUInteger calculatedDistance = 0; for (NSUInteger i = 0; i < self.firstStrand.length; i++) { unichar firstGene = [self.firstStrand characterAtIndex:i]; unichar secondGene = [self.secondStrand characterAtIndex:i]; if ([self mutationBetween:firstGene and:secondGene]) { calculatedDistance ++; } } return calculatedDistance; } - (BOOL)mutationBetween:(unichar)firstGene and:(unichar)secondGene { return (firstGene != secondGene); } @end
Version data entries
396 entries across 396 versions & 1 rubygems