Created
March 3, 2020 16:19
-
-
Save fardinabir/f103cb262a9481b1a66396748969ad64 to your computer and use it in GitHub Desktop.
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
#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