Created
December 7, 2012 01:27
-
-
Save shannah/4230001 to your computer and use it in GitHub Desktop.
Towers of Hanoi using objective-c messages.
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
#import "com_mycompany_myapp_NativeTowersOfHanoiImpl.h" | |
@implementation com_mycompany_myapp_NativeTowersOfHanoiImpl | |
-(void)move:(int)n startPole:(int)startPole endPole:(int)endPole | |
{ | |
if (n == 0) { | |
return; | |
} | |
int intermediatePole = 6 - startPole - endPole; | |
[self move:n-1 startPole:startPole endPole:intermediatePole]; | |
[self move:n-1 startPole:intermediatePole endPole:endPole]; | |
counter++; | |
} | |
-(int)runCalculation{ | |
counter = 0; | |
[self move:30 startPole:1 endPole:3]; | |
return counter; | |
} | |
-(BOOL)isSupported{ | |
return YES; | |
} | |
@end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment