Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shannah/4230001 to your computer and use it in GitHub Desktop.
Save shannah/4230001 to your computer and use it in GitHub Desktop.
Towers of Hanoi using objective-c messages.
#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