#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)
moveDisks(from,to,n-1);
moveOneDisk(from,anotherPole);
moveOneDisk(from,to);
moveOneDisk(anotherPole,to);
moveOneDisk(from,anotherPole);
moveOneDisk(to,anotherPole);
moveOneDisk(to,from);
moveOneDisk(anotherPole,from);
moveOneDisk(anotherPole,to);
}
int main(void) {
int n = 5;
printf("%d枚の円盤を杭1から杭3に移動させる手順は以下のとおり:\n",n
);moveDisks
(1, 3, n
); return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CnZvaWQgbW92ZU9uZURpc2soaW50IGZyb20sIGludCB0bykgewpwcmludGYoIuadrSVk44GL44KJ5p2tJWTjgavnp7vli5VcbiIsIGZyb20sIHRvKTsKfQp2b2lkIG1vdmVEaXNrcyhpbnQgZnJvbSwgaW50IHRvICwgaW50IG4pIHsKaW50IGFub3RoZXJQb2xlID0gNi0oZnJvbSt0byk7CglpZihuPjEpCgltb3ZlRGlza3MoZnJvbSx0byxuLTEpOwoJCgltb3ZlT25lRGlzayhmcm9tLGFub3RoZXJQb2xlKTsKCW1vdmVPbmVEaXNrKGZyb20sdG8pOwoJbW92ZU9uZURpc2soYW5vdGhlclBvbGUsdG8pOwoJbW92ZU9uZURpc2soZnJvbSxhbm90aGVyUG9sZSk7Cgltb3ZlT25lRGlzayh0byxhbm90aGVyUG9sZSk7Cgltb3ZlT25lRGlzayh0byxmcm9tKTsKCW1vdmVPbmVEaXNrKGFub3RoZXJQb2xlLGZyb20pOwoJCW1vdmVPbmVEaXNrKGFub3RoZXJQb2xlLHRvKTsKCgkKCQoJCgkKfQoKCgppbnQgbWFpbih2b2lkKSB7CmludCBuID0gNTsKcHJpbnRmKCIlZOaemuOBruWGhuebpOOCkuadrTHjgYvjgonmna0z44Gr56e75YuV44GV44Gb44KL5omL6aCG44Gv5Lul5LiL44Gu44Go44GK44KK77yaXG4iLG4pO21vdmVEaXNrcygxLCAzLCBuKTsKcmV0dXJuIDA7Cn0=