Recursive Karakuri Treasure Chest Puzzle Solution in C

// Recursive definitions:
// Assume levers are named a..f from small to large.
// Then solution is R(6), wherein
// R(n)=R(n-1),pr(n),V(n-1),pr(n) and R(0)=Null, wherein
// V(n)=pr(n),V(n-1),pr(n) and V(0)=Null.

#include "stdafx.h"
int c=1;
void pr(int n){printf("%2d",c++);for(int i=0;i<n;i++) printf(" ");printf("%c\n",n+96);}
void V(int n){if(n){pr(n);V(n-1);pr(n);}}
void R(int n){if(n){R(n-1);pr(n);V(n-1);pr(n);}}
void main(){R(6);c=getchar();}


last update 01/21/11