Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save shannah/4229088 to your computer and use it in GitHub Desktop.
Save shannah/4229088 to your computer and use it in GitHub Desktop.
Revised Towers of Hanoi Benchmark with static variable that is incremented.
#import "com_mycompany_myapp_NativeTowersOfHanoiImpl.h"
static counter = 0;
void com_mycompany_myapp_NativeTowersOfHanoiImpl_move(int n, int startPole, int endPole) {
if (n == 0) {
return;
}
int intermediatePole = 6 - startPole - endPole;
com_mycompany_myapp_NativeTowersOfHanoiImpl_move(n - 1, startPole, intermediatePole);
//NSLog(@"Move %i from %i to %i", n, startPole, endPole);
com_mycompany_myapp_NativeTowersOfHanoiImpl_move(n - 1, intermediatePole, endPole);
counter++;
}
@implementation com_mycompany_myapp_NativeTowersOfHanoiImpl
-(int)runCalculation{
com_mycompany_myapp_NativeTowersOfHanoiImpl_move(30, 1, 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