#include <stdio.h>
void moveOneDisk(int from, int to) {
printf("杭%dから杭%dに移動\n", from
, to
); }
void moveDisks(int from, int to , int n) {
int anotherPole = 6-(from+to);
if( n == 1 ) {
moveOneDisk(from, to);
} else {
moveDisks(from, anotherPole, n-1);
moveOneDisk(from, to);
moveDisks(anotherPole, to, n-1);
}
}
int main(void) {
int n = 2;
printf("%d枚の円盤を杭1から杭3に移動させる手順は以下のとおり:\n", n
); moveDisks(1, 3, n);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CnZvaWQgbW92ZU9uZURpc2soaW50IGZyb20sIGludCB0bykgewpwcmludGYoIuadrSVk44GL44KJ5p2tJWTjgavnp7vli5VcbiIsIGZyb20sIHRvKTsKfQp2b2lkIG1vdmVEaXNrcyhpbnQgZnJvbSwgaW50IHRvICwgaW50IG4pIHsKaW50IGFub3RoZXJQb2xlID0gNi0oZnJvbSt0byk7CmlmKCBuID09IDEgKSB7Cm1vdmVPbmVEaXNrKGZyb20sIHRvKTsKfSBlbHNlIHsKbW92ZURpc2tzKGZyb20sIGFub3RoZXJQb2xlLCBuLTEpOwptb3ZlT25lRGlzayhmcm9tLCB0byk7Cm1vdmVEaXNrcyhhbm90aGVyUG9sZSwgdG8sIG4tMSk7Cn0KfQppbnQgbWFpbih2b2lkKSB7CmludCBuID0gMjsKcHJpbnRmKCIlZOaemuOBruWGhuebpOOCkuadrTHjgYvjgonmna0z44Gr56e75YuV44GV44Gb44KL5omL6aCG44Gv5Lul5LiL44Gu44Go44GK44KK77yaXG4iLCBuKTsKbW92ZURpc2tzKDEsIDMsIG4pOwpyZXR1cm4gMDsKfQ==