This repository has been archived by the owner on Apr 10, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit. Need to update README
- Loading branch information
MaxKramer
committed
Dec 30, 2012
1 parent
e6dc3b2
commit d7da3e6
Showing
19 changed files
with
1,408 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// Luhn.h | ||
// Luhn Algorithm (Mod 10) | ||
// | ||
// Created by Max Kramer on 30/12/2012. | ||
// Copyright (c) 2012 Max Kramer. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface Luhn : NSObject | ||
|
||
+ (BOOL) validateString:(NSString *) ccString; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// Luhn.m | ||
// Luhn Algorithm (Mod 10) | ||
// | ||
// Created by Max Kramer on 30/12/2012. | ||
// Copyright (c) 2012 Max Kramer. All rights reserved. | ||
// | ||
|
||
#import "Luhn.h" | ||
|
||
@implementation Luhn | ||
|
||
+ (BOOL) validateString:(NSString *) _string { | ||
|
||
NSMutableString *reversedString = [NSMutableString stringWithCapacity:[_string length]]; | ||
|
||
[_string enumerateSubstringsInRange:NSMakeRange(0, [_string length]) options:(NSStringEnumerationReverse |NSStringEnumerationByComposedCharacterSequences) usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) { | ||
[reversedString appendString:substring]; | ||
}]; | ||
|
||
unsigned int odd_sum = 0, even_sum = 0; | ||
|
||
for (int i = 0; i < [reversedString length]; i++) { | ||
|
||
NSInteger digit = [[NSString stringWithFormat:@"%C", [reversedString characterAtIndex:i]] integerValue]; | ||
|
||
if (i % 2 == 0) { | ||
|
||
odd_sum += digit; | ||
|
||
} | ||
|
||
else { | ||
|
||
even_sum += digit / 5 + ( 2 * digit) % 10; | ||
|
||
} | ||
|
||
} | ||
|
||
return (odd_sum + even_sum) % 10 == 0; | ||
|
||
} | ||
|
||
@end |
314 changes: 314 additions & 0 deletions
314
Example Project/Luhn Algorithm (Mod 10).xcodeproj/project.pbxproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,314 @@ | ||
// !$*UTF8*$! | ||
{ | ||
archiveVersion = 1; | ||
classes = { | ||
}; | ||
objectVersion = 46; | ||
objects = { | ||
|
||
/* Begin PBXBuildFile section */ | ||
501B5F58168FD59700726E65 /* Luhn.m in Sources */ = {isa = PBXBuildFile; fileRef = 501B5F57168FD58B00726E65 /* Luhn.m */; }; | ||
508E0A63168FC92800F237F4 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 508E0A62168FC92800F237F4 /* UIKit.framework */; }; | ||
508E0A65168FC92800F237F4 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 508E0A64168FC92800F237F4 /* Foundation.framework */; }; | ||
508E0A67168FC92800F237F4 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 508E0A66168FC92800F237F4 /* CoreGraphics.framework */; }; | ||
508E0A6D168FC92800F237F4 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 508E0A6B168FC92800F237F4 /* InfoPlist.strings */; }; | ||
508E0A6F168FC92800F237F4 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 508E0A6E168FC92800F237F4 /* main.m */; }; | ||
508E0A73168FC92800F237F4 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 508E0A72168FC92800F237F4 /* AppDelegate.m */; }; | ||
508E0A75168FC92800F237F4 /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = 508E0A74168FC92800F237F4 /* Default.png */; }; | ||
508E0A77168FC92800F237F4 /* Default@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 508E0A76168FC92800F237F4 /* Default@2x.png */; }; | ||
508E0A79168FC92800F237F4 /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 508E0A78168FC92800F237F4 /* Default-568h@2x.png */; }; | ||
508E0A7C168FC92800F237F4 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 508E0A7B168FC92800F237F4 /* ViewController.m */; }; | ||
508E0A7F168FC92800F237F4 /* ViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 508E0A7D168FC92800F237F4 /* ViewController.xib */; }; | ||
/* End PBXBuildFile section */ | ||
|
||
/* Begin PBXFileReference section */ | ||
501B5F56168FD58B00726E65 /* Luhn.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Luhn.h; sourceTree = "<group>"; }; | ||
501B5F57168FD58B00726E65 /* Luhn.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Luhn.m; sourceTree = "<group>"; }; | ||
508E0A5E168FC92800F237F4 /* Luhn Algorithm (Mod 10).app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Luhn Algorithm (Mod 10).app"; sourceTree = BUILT_PRODUCTS_DIR; }; | ||
508E0A62168FC92800F237F4 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; | ||
508E0A64168FC92800F237F4 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; | ||
508E0A66168FC92800F237F4 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; | ||
508E0A6A168FC92800F237F4 /* Luhn Algorithm (Mod 10)-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Luhn Algorithm (Mod 10)-Info.plist"; sourceTree = "<group>"; }; | ||
508E0A6C168FC92800F237F4 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; }; | ||
508E0A6E168FC92800F237F4 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; }; | ||
508E0A70168FC92800F237F4 /* Luhn Algorithm (Mod 10)-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Luhn Algorithm (Mod 10)-Prefix.pch"; sourceTree = "<group>"; }; | ||
508E0A71168FC92800F237F4 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; }; | ||
508E0A72168FC92800F237F4 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; }; | ||
508E0A74168FC92800F237F4 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = "<group>"; }; | ||
508E0A76168FC92800F237F4 /* Default@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default@2x.png"; sourceTree = "<group>"; }; | ||
508E0A78168FC92800F237F4 /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = "<group>"; }; | ||
508E0A7A168FC92800F237F4 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = "<group>"; }; | ||
508E0A7B168FC92800F237F4 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; }; | ||
508E0A7E168FC92800F237F4 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/ViewController.xib; sourceTree = "<group>"; }; | ||
/* End PBXFileReference section */ | ||
|
||
/* Begin PBXFrameworksBuildPhase section */ | ||
508E0A5B168FC92800F237F4 /* Frameworks */ = { | ||
isa = PBXFrameworksBuildPhase; | ||
buildActionMask = 2147483647; | ||
files = ( | ||
508E0A63168FC92800F237F4 /* UIKit.framework in Frameworks */, | ||
508E0A65168FC92800F237F4 /* Foundation.framework in Frameworks */, | ||
508E0A67168FC92800F237F4 /* CoreGraphics.framework in Frameworks */, | ||
); | ||
runOnlyForDeploymentPostprocessing = 0; | ||
}; | ||
/* End PBXFrameworksBuildPhase section */ | ||
|
||
/* Begin PBXGroup section */ | ||
50676D08168FD23E00218207 /* Luhn Algorithm */ = { | ||
isa = PBXGroup; | ||
children = ( | ||
501B5F56168FD58B00726E65 /* Luhn.h */, | ||
501B5F57168FD58B00726E65 /* Luhn.m */, | ||
); | ||
name = "Luhn Algorithm"; | ||
path = "Luhn Algorithm (Mod 10)"; | ||
sourceTree = "<group>"; | ||
}; | ||
508E0A53168FC92800F237F4 = { | ||
isa = PBXGroup; | ||
children = ( | ||
50676D08168FD23E00218207 /* Luhn Algorithm */, | ||
508E0A68168FC92800F237F4 /* Example Project */, | ||
508E0A61168FC92800F237F4 /* Frameworks */, | ||
508E0A5F168FC92800F237F4 /* Products */, | ||
); | ||
sourceTree = "<group>"; | ||
}; | ||
508E0A5F168FC92800F237F4 /* Products */ = { | ||
isa = PBXGroup; | ||
children = ( | ||
508E0A5E168FC92800F237F4 /* Luhn Algorithm (Mod 10).app */, | ||
); | ||
name = Products; | ||
sourceTree = "<group>"; | ||
}; | ||
508E0A61168FC92800F237F4 /* Frameworks */ = { | ||
isa = PBXGroup; | ||
children = ( | ||
508E0A62168FC92800F237F4 /* UIKit.framework */, | ||
508E0A64168FC92800F237F4 /* Foundation.framework */, | ||
508E0A66168FC92800F237F4 /* CoreGraphics.framework */, | ||
); | ||
name = Frameworks; | ||
sourceTree = "<group>"; | ||
}; | ||
508E0A68168FC92800F237F4 /* Example Project */ = { | ||
isa = PBXGroup; | ||
children = ( | ||
508E0A71168FC92800F237F4 /* AppDelegate.h */, | ||
508E0A72168FC92800F237F4 /* AppDelegate.m */, | ||
508E0A7A168FC92800F237F4 /* ViewController.h */, | ||
508E0A7B168FC92800F237F4 /* ViewController.m */, | ||
508E0A7D168FC92800F237F4 /* ViewController.xib */, | ||
508E0A69168FC92800F237F4 /* Supporting Files */, | ||
); | ||
name = "Example Project"; | ||
path = "Luhn Algorithm (Mod 10)"; | ||
sourceTree = "<group>"; | ||
}; | ||
508E0A69168FC92800F237F4 /* Supporting Files */ = { | ||
isa = PBXGroup; | ||
children = ( | ||
508E0A6A168FC92800F237F4 /* Luhn Algorithm (Mod 10)-Info.plist */, | ||
508E0A6B168FC92800F237F4 /* InfoPlist.strings */, | ||
508E0A6E168FC92800F237F4 /* main.m */, | ||
508E0A70168FC92800F237F4 /* Luhn Algorithm (Mod 10)-Prefix.pch */, | ||
508E0A74168FC92800F237F4 /* Default.png */, | ||
508E0A76168FC92800F237F4 /* Default@2x.png */, | ||
508E0A78168FC92800F237F4 /* Default-568h@2x.png */, | ||
); | ||
name = "Supporting Files"; | ||
sourceTree = "<group>"; | ||
}; | ||
/* End PBXGroup section */ | ||
|
||
/* Begin PBXNativeTarget section */ | ||
508E0A5D168FC92800F237F4 /* Luhn Algorithm (Mod 10) */ = { | ||
isa = PBXNativeTarget; | ||
buildConfigurationList = 508E0A82168FC92800F237F4 /* Build configuration list for PBXNativeTarget "Luhn Algorithm (Mod 10)" */; | ||
buildPhases = ( | ||
508E0A5A168FC92800F237F4 /* Sources */, | ||
508E0A5B168FC92800F237F4 /* Frameworks */, | ||
508E0A5C168FC92800F237F4 /* Resources */, | ||
); | ||
buildRules = ( | ||
); | ||
dependencies = ( | ||
); | ||
name = "Luhn Algorithm (Mod 10)"; | ||
productName = "Luhn Algorithm (Mod 10)"; | ||
productReference = 508E0A5E168FC92800F237F4 /* Luhn Algorithm (Mod 10).app */; | ||
productType = "com.apple.product-type.application"; | ||
}; | ||
/* End PBXNativeTarget section */ | ||
|
||
/* Begin PBXProject section */ | ||
508E0A55168FC92800F237F4 /* Project object */ = { | ||
isa = PBXProject; | ||
attributes = { | ||
LastUpgradeCheck = 0450; | ||
ORGANIZATIONNAME = "Max Kramer"; | ||
}; | ||
buildConfigurationList = 508E0A58168FC92800F237F4 /* Build configuration list for PBXProject "Luhn Algorithm (Mod 10)" */; | ||
compatibilityVersion = "Xcode 3.2"; | ||
developmentRegion = English; | ||
hasScannedForEncodings = 0; | ||
knownRegions = ( | ||
en, | ||
); | ||
mainGroup = 508E0A53168FC92800F237F4; | ||
productRefGroup = 508E0A5F168FC92800F237F4 /* Products */; | ||
projectDirPath = ""; | ||
projectRoot = ""; | ||
targets = ( | ||
508E0A5D168FC92800F237F4 /* Luhn Algorithm (Mod 10) */, | ||
); | ||
}; | ||
/* End PBXProject section */ | ||
|
||
/* Begin PBXResourcesBuildPhase section */ | ||
508E0A5C168FC92800F237F4 /* Resources */ = { | ||
isa = PBXResourcesBuildPhase; | ||
buildActionMask = 2147483647; | ||
files = ( | ||
508E0A6D168FC92800F237F4 /* InfoPlist.strings in Resources */, | ||
508E0A75168FC92800F237F4 /* Default.png in Resources */, | ||
508E0A77168FC92800F237F4 /* Default@2x.png in Resources */, | ||
508E0A79168FC92800F237F4 /* Default-568h@2x.png in Resources */, | ||
508E0A7F168FC92800F237F4 /* ViewController.xib in Resources */, | ||
); | ||
runOnlyForDeploymentPostprocessing = 0; | ||
}; | ||
/* End PBXResourcesBuildPhase section */ | ||
|
||
/* Begin PBXSourcesBuildPhase section */ | ||
508E0A5A168FC92800F237F4 /* Sources */ = { | ||
isa = PBXSourcesBuildPhase; | ||
buildActionMask = 2147483647; | ||
files = ( | ||
508E0A6F168FC92800F237F4 /* main.m in Sources */, | ||
508E0A73168FC92800F237F4 /* AppDelegate.m in Sources */, | ||
508E0A7C168FC92800F237F4 /* ViewController.m in Sources */, | ||
501B5F58168FD59700726E65 /* Luhn.m in Sources */, | ||
); | ||
runOnlyForDeploymentPostprocessing = 0; | ||
}; | ||
/* End PBXSourcesBuildPhase section */ | ||
|
||
/* Begin PBXVariantGroup section */ | ||
508E0A6B168FC92800F237F4 /* InfoPlist.strings */ = { | ||
isa = PBXVariantGroup; | ||
children = ( | ||
508E0A6C168FC92800F237F4 /* en */, | ||
); | ||
name = InfoPlist.strings; | ||
sourceTree = "<group>"; | ||
}; | ||
508E0A7D168FC92800F237F4 /* ViewController.xib */ = { | ||
isa = PBXVariantGroup; | ||
children = ( | ||
508E0A7E168FC92800F237F4 /* en */, | ||
); | ||
name = ViewController.xib; | ||
sourceTree = "<group>"; | ||
}; | ||
/* End PBXVariantGroup section */ | ||
|
||
/* Begin XCBuildConfiguration section */ | ||
508E0A80168FC92800F237F4 /* Debug */ = { | ||
isa = XCBuildConfiguration; | ||
buildSettings = { | ||
ALWAYS_SEARCH_USER_PATHS = NO; | ||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; | ||
CLANG_CXX_LIBRARY = "libc++"; | ||
CLANG_WARN_EMPTY_BODY = YES; | ||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; | ||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; | ||
COPY_PHASE_STRIP = NO; | ||
GCC_C_LANGUAGE_STANDARD = gnu99; | ||
GCC_DYNAMIC_NO_PIC = NO; | ||
GCC_OPTIMIZATION_LEVEL = 0; | ||
GCC_PREPROCESSOR_DEFINITIONS = ( | ||
"DEBUG=1", | ||
"$(inherited)", | ||
); | ||
GCC_SYMBOLS_PRIVATE_EXTERN = NO; | ||
GCC_WARN_ABOUT_RETURN_TYPE = YES; | ||
GCC_WARN_UNINITIALIZED_AUTOS = YES; | ||
GCC_WARN_UNUSED_VARIABLE = YES; | ||
IPHONEOS_DEPLOYMENT_TARGET = 6.0; | ||
ONLY_ACTIVE_ARCH = YES; | ||
SDKROOT = iphoneos; | ||
}; | ||
name = Debug; | ||
}; | ||
508E0A81168FC92800F237F4 /* Release */ = { | ||
isa = XCBuildConfiguration; | ||
buildSettings = { | ||
ALWAYS_SEARCH_USER_PATHS = NO; | ||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; | ||
CLANG_CXX_LIBRARY = "libc++"; | ||
CLANG_WARN_EMPTY_BODY = YES; | ||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; | ||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; | ||
COPY_PHASE_STRIP = YES; | ||
GCC_C_LANGUAGE_STANDARD = gnu99; | ||
GCC_WARN_ABOUT_RETURN_TYPE = YES; | ||
GCC_WARN_UNINITIALIZED_AUTOS = YES; | ||
GCC_WARN_UNUSED_VARIABLE = YES; | ||
IPHONEOS_DEPLOYMENT_TARGET = 6.0; | ||
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; | ||
SDKROOT = iphoneos; | ||
VALIDATE_PRODUCT = YES; | ||
}; | ||
name = Release; | ||
}; | ||
508E0A83168FC92800F237F4 /* Debug */ = { | ||
isa = XCBuildConfiguration; | ||
buildSettings = { | ||
GCC_PRECOMPILE_PREFIX_HEADER = YES; | ||
GCC_PREFIX_HEADER = "Luhn Algorithm (Mod 10)/Luhn Algorithm (Mod 10)-Prefix.pch"; | ||
INFOPLIST_FILE = "Luhn Algorithm (Mod 10)/Luhn Algorithm (Mod 10)-Info.plist"; | ||
PRODUCT_NAME = "$(TARGET_NAME)"; | ||
WRAPPER_EXTENSION = app; | ||
}; | ||
name = Debug; | ||
}; | ||
508E0A84168FC92800F237F4 /* Release */ = { | ||
isa = XCBuildConfiguration; | ||
buildSettings = { | ||
GCC_PRECOMPILE_PREFIX_HEADER = YES; | ||
GCC_PREFIX_HEADER = "Luhn Algorithm (Mod 10)/Luhn Algorithm (Mod 10)-Prefix.pch"; | ||
INFOPLIST_FILE = "Luhn Algorithm (Mod 10)/Luhn Algorithm (Mod 10)-Info.plist"; | ||
PRODUCT_NAME = "$(TARGET_NAME)"; | ||
WRAPPER_EXTENSION = app; | ||
}; | ||
name = Release; | ||
}; | ||
/* End XCBuildConfiguration section */ | ||
|
||
/* Begin XCConfigurationList section */ | ||
508E0A58168FC92800F237F4 /* Build configuration list for PBXProject "Luhn Algorithm (Mod 10)" */ = { | ||
isa = XCConfigurationList; | ||
buildConfigurations = ( | ||
508E0A80168FC92800F237F4 /* Debug */, | ||
508E0A81168FC92800F237F4 /* Release */, | ||
); | ||
defaultConfigurationIsVisible = 0; | ||
defaultConfigurationName = Release; | ||
}; | ||
508E0A82168FC92800F237F4 /* Build configuration list for PBXNativeTarget "Luhn Algorithm (Mod 10)" */ = { | ||
isa = XCConfigurationList; | ||
buildConfigurations = ( | ||
508E0A83168FC92800F237F4 /* Debug */, | ||
508E0A84168FC92800F237F4 /* Release */, | ||
); | ||
defaultConfigurationIsVisible = 0; | ||
defaultConfigurationName = Release; | ||
}; | ||
/* End XCConfigurationList section */ | ||
}; | ||
rootObject = 508E0A55168FC92800F237F4 /* Project object */; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// AppDelegate.h | ||
// Luhn Algorithm (Mod 10) | ||
// | ||
// Created by Max Kramer on 30/12/2012. | ||
// Copyright (c) 2012 Max Kramer. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@class ViewController; | ||
|
||
@interface AppDelegate : UIResponder <UIApplicationDelegate> | ||
|
||
@property (strong, nonatomic) UIWindow *window; | ||
|
||
@property (strong, nonatomic) ViewController *viewController; | ||
|
||
@end |
Oops, something went wrong.