Skip to content

Instantly share code, notes, and snippets.

@fardinabir
Created March 3, 2020 16:19
Show Gist options
  • Save fardinabir/f103cb262a9481b1a66396748969ad64 to your computer and use it in GitHub Desktop.
Save fardinabir/f103cb262a9481b1a66396748969ad64 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int cnt;
void solve(int n,char from,char to,char aux)
{
cnt++;
if(n==1)
{
printf("Move %d from %c -- to %c\n",n,from,to);
return;
}
solve(n-1,from,aux,to);
printf("Move %d from %c -- to %c\n",n,from,to);
solve(n-1,aux,to,from);
}
int main()
{
int n;
cin>>n;
solve(n,'A','B','C');
printf("\nSolved at %d moves\n",cnt);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment