I've been working on a method that returns the minimum number of moves that can be made in the Tower of Hanoi game complacently based on the number of rings. So far I have the basic code that can calculate 2^n (n being the number of rings). However, when I go to subtract 1 the method behaves as if their are no rings.
static int countHanoiMoves(int n)
{
int unSubtrctAnswer = 0;
if(n == 0)
{
return 1;
}
int halfPower = countHanoiMoves(n / 2);
if (n % 2 == 1)
{
unSubtrctAnswer = (2 * halfPower * halfPower);
}
else
{
unSubtrctAnswer = (halfPower * halfPower);
}
return unSubtrctAnswer - 1;
}