{"id":1574,"date":"2014-12-12T18:47:41","date_gmt":"2014-12-12T23:47:41","guid":{"rendered":"http:\/\/www.a2life.info\/w\/?p=1574"},"modified":"2014-12-16T08:13:44","modified_gmt":"2014-12-16T13:13:44","slug":"%e3%83%8f%e3%83%8e%e3%82%a4%e3%81%ae%e5%a1%94%e3%82%92%e8%a7%a3%e3%81%8fsolving-towers-of-hanoi","status":"publish","type":"post","link":"https:\/\/www.a2life.info\/w\/?p=1574","title":{"rendered":"\u30cf\u30ce\u30a4\u306e\u5854\u3092\u89e3\u304f(Solving Towers of Hanoi)"},"content":{"rendered":"<p>\u30cf\u30ce\u30a4\u306e\u5854\u3068\u3044\u3046\u306e\u306f\u30d1\u30ba\u30eb\u3060\u304c\u3001\u30ea\u30ab\u30fc\u30b8\u30e7\u30f3\u3068\u3044\u3046\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u306b\u3088\u304f\u306a\u3058\u3080\u306e\u3067\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u6559\u79d1\u66f8\u306b\u51fa\u3066\u3044\u308b\u3053\u3068\u304c\u3042\u308b\u3002\u3000\u81ea\u5206\u304c\u3053\u308c\u3092\u898b\u305f\u306e\u306f&#8221;Oh Pascal!&#8221;\u3068\u3044\u3046\u30d1\u30b9\u30ab\u30eb\u306e\u5165\u9580\u66f8\u306730\u5e74\u304f\u3089\u3044\u524d\u306b\u767a\u884c\u3055\u308c\u305f\u5b66\u751f\u5411\u3051\u306e\u6559\u79d1\u66f8\u3060\u3002<br \/>\n\u30d1\u30ba\u30eb\u306e\u5185\u5bb9\u306f\u3053\u3093\u306a\u5177\u5408\u3002<br \/>\n\uff11\uff0e3\u672c\u306e\u68d2\u304c\u7acb\u3063\u3066\u3044\u308b\u3002\u4eee\u306b\u3053\u308c\u3092\u53f3\u304b\u3089A,B,C\u3068\u3059\u308b\u3002<br \/>\n\uff12\uff0eA\u306b\u306f\u771f\u3093\u4e2d\u306b\u7a74\u306e\u3042\u3044\u305f\u5186\u76e4\u304c\u7a4d\u307f\u4e0a\u3052\u3066\u3042\u308b\u3002\u5186\u76e4\u306e\u76f4\u5f84\u306f\u5e95\u306b\u3042\u308b\u3082\u306e\u304c\u4e00\u756a\u5927\u304d\u304f\u3001\u4e0a\u306b\u884c\u304f\u307b\u3069\u5c0f\u3055\u304f\u306a\u308b\u3002<br \/>\n\uff13\uff0e\u4e00\u5ea6\u306b\u4e00\u500b\u305a\u3064\u3053\u306e\u3053\u306e\u5186\u76e4\u3092\u53d6\u308a\u51fa\u3057\u3066\u4ed6\u306e\u68d2\u306b\u79fb\u3059\u3053\u3068\u304c\u3067\u304d\u308b\u3002\u6700\u7d42\u7684\u306b\u306f\u5168\u90e8\u306e\u5186\u76e4\u3092C\u306b\u79fb\u3057\u305f\u3044\u3002<br \/>\n\uff14\uff0e\u305f\u3060\u3057\u3001\u5927\u304d\u306a\u5186\u76e4\u3092\u5c0f\u3055\u306a\u5186\u76e4\u306e\u4e0a\u306b\u7f6e\u304f\u3053\u3068\u306f\u3067\u304d\u306a\u3044\u3002<\/p>\n<p>Hanoi\u306e\u5854\u3068\u3044\u3046\u306e\u306f\u3053\u306e\u201d\u91d1\u306e\u201d\u5186\u76e4\u309264\u679a\u7a4d\u307f\u4e0a\u3052\u305f\u3082\u306e\u3060\u305d\u3046\u3067\u3001\u3053\u306e\u30d1\u30ba\u30eb\u304c\u89e3\u3051\u305f\u3068\u304d\u306b\u306f\u4e16\u306e\u4e2d\u304c\u7d42\u7109\u3092\u8fce\u3048\u308b\u3001\u3068\u3044\u3046\u30aa\u30c8\u30ed\u3057\u3044\u843d\u3061\u304c\u3064\u3044\u3066\u3044\u308b\u3002<\/p>\n<p>\u3053\u308c\u3092\u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u30fc\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4f7f\u3063\u3066\u89e3\u304f\u3068\u3069\u3046\u306a\u308b\u304b\u3001\u3068\u3044\u3046\u8a71\u3067\u3042\u308b\u3002\u3000\u30d1\u30bf\u30fc\u30f3\u3092\u898b\u3064\u3051\u308b\u305f\u3081\u306b\u5c11\u306a\u3044\u679a\u6570\u3067\u5b9f\u969b\u306b\u89e3\u304f\u3053\u3068\u3092\u8a66\u307f\u308b\u3002<br \/>\nDisk(\u5186\u76e4\uff09\u306e\u6570\u304c\u4e00\u679a\u306e\u6642\u306b\u306f\u7c21\u5358\u3060\u3002\u5186\u76e4\u3092A\u304b\u3089C\u306b\u79fb\u305b\u3070\u3088\u3044\u3002<\/p>\n<pre>\r\nMove(1disk from A to C) =\u3000Move a Disk from A to C\r\n<\/pre>\n<p>\u3067\u306f2\u679a\u306e\u6642\u306b\u306f\u3069\u3046\u306a\u308b\u304b<\/p>\n<pre>\r\nMove(2disks from A to C) = \r\n Move a Disk from A to B\r\n Move a Disk from A to C\r\n Move a Disk from B to C\r\n<\/pre>\n<p>\u3053\u3053\u3067\u68d2B\u3092\u4f7f\u3046\u3053\u3068\u306b\u306a\u308b\u3002\u3000\u3064\u307e\u308a\u3001\u307e\u305a\u4e0a\u306e\u5186\u76e4\u3092\u68d2A\u304b\u3089B\u306b\u79fb\u3057\u3001\u4e0b\u306e\u5186\u76e4\u3092A\u304b\u3089C\u3078\u3001\u6700\u5f8c\u306bB\u306b\u79fb\u3057\u3066\u3042\u3063\u305f\u5186\u76e4\u3092C\u306b\u79fb\u3057\u3066\u5b8c\u6210\u3060\u3002<\/p>\n<pre>\r\nMove (2 disks from A to C)\u3000= Move (2 disks from A to C using B)\r\n<\/pre>\n<p>3\u679a\u306f\u3069\u3046\u304b\u3002\u3000\u3059\u3067\u306b2\u679a\u3092\u52d5\u304b\u3059\u65b9\u6cd5\u306f\u308f\u304b\u3063\u3066\u3044\u308b\u306e\u305d\u306e\u65b9\u6cd5\u3092\u4f7f\u3063\u3066\u307e\u305a\u306f2\u679a\u3092B\u306b\u52d5\u304b\u3057\u3066\u304a\u304d\u3001\u6700\u5f8c\u306e\u4e00\u679a\u3092A\u304b\u3089C\u306b\u79fb\u52d5\u3001\u3055\u3089\u306b2\u679a\u3092\u52d5\u304b\u3059\u65b9\u6cd5\u3092\u4f7f\u3063\u3066B\u304b\u3089C\u306b\u79fb\u52d5\u3059\u308b\u3068\u3044\u3046\u65b9\u6cd5\u3067\u52d5\u304b\u305b\u308b\u3002<\/p>\n<pre>\r\nMove(3 disks from A to C using B)\u3000=\r\n Move(2 disks from A to B using C)\r\n Move a disk from A to C\r\n Move (2 disks from B to c using A)\r\n<\/pre>\n<p>4\u679a\u306e\u5834\u5408\u3082\u540c\u69d8\u306b\u8003\u3048\u3089\u308c\u308b\u306e\u3067\u30d1\u30bf\u30fc\u30f3\u3068\u3057\u3066\u306f\u3000(n-1)\u679a\u306e\u5186\u76e4\u3092A\u304b\u3089B\u306b\u79fb\u3059\u3002\u6700\u5f8c\u306e\u5186\u76e4\u3092A\u304b\u3089C\u306b\u79fb\u52d5\u3057\u3001\u305d\u306e\u5f8c(n-1)\u679a\u306e\u5186\u76e4\u3092B\u304b\u3089C\u306b\u79fb\u3059\u3002\u3000\u3068\u3044\u3046\u3053\u3068\u306b\u306a\u308b\u3002<\/p>\n<pre>\r\nMove (n disks from A to C using B) =\r\n if n>2 Move (n-1 disks from A to B using C)\r\n Move a disk from A to C\r\n if n>2 Move (n-1 disks from B to C using A)\r\n<\/pre>\n<p>\u3053\u306e\u30d1\u30bf-\u30f3\u3092\u4f7f\u3063\u3066\u95a2\u6570\u3092\u66f8\u304f\u3068\u3001\u81ea\u5206\u3067\u81ea\u5206\u81ea\u8eab\u3092\u547c\u3073\u3060\u3059\u95a2\u6570\u306b\u306a\u308b\u3002\u3053\u308c\u304c\u3044\u308f\u3086\u308bRecursion \u3068\u547c\u3070\u308c\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u30c6\u30af\u30cb\u30c3\u30af\u3060\u304cC\u3067\u3082Pascal\u3067\u3082PHP\u3067\u3082\u3044\u307e\u3069\u304d\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u306a\u3089\u8ed2\u4e26\u307f\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u3066\u3044\u308b\u3002\u305f\u3060\u3057\u666e\u901a\u306e\u30eb\u30fc\u30d7\u306b\u6bd4\u3079\u308b\u3068\u30b9\u30bf\u30c3\u30af\u306b\u3069\u3093\u3069\u3093\u81ea\u5206\u306e\u30b3\u30d4\u30fc\u3092\u7a4d\u3093\u3067\u3044\u304f\u305f\u3081\u30e1\u30e2\u30ea\u30fc\u3092\u6d88\u8cbb\u3057\u3001\u6614\u306e8\u30d3\u30c3\u30c8\u30d1\u30bd\u30b3\u30f3\u3067\u306f\u4f55\u305bRAM\u304c32\u30ad\u30ed\u30d0\u30a4\u30c8\u3042\u308c\u3070\u9ad8\u7d1a\u6a5f\u3001\u8a08\u7b97\u3057\u3066\u3044\u308b\u3046\u3061\u306b\u30e1\u30e2\u30ea\u30fc\u304c\u8db3\u308a\u306a\u304f\u306a\u308b\u3001\u306a\u3093\u3066\u3053\u3068\u3082\u3042\u3063\u305f\u308a\u3057\u3066\u3001Loop\u3067\u8a18\u8ff0\u3067\u304d\u308b\u3082\u306e\u306fRecursion\u3092\u3055\u3051\u308b\u3001\u3068\u3044\u3046\u306e\u304c\u5e38\u8b58\u3060\u3063\u305f\u3002<br \/>\n\u3057\u304b\u3057\u306a\u304c\u3089\u3053\u306e\u8a18\u8ff0\u306e\u7c21\u4fbf\u3055\u3001\u77ed\u3055\u306f\u611f\u52d5\u3082\u306e\u3067\u3042\u308b\u3002\u4eca\u306e\u30d1\u30bd\u30b3\u30f3\u306f\u305d\u3093\u306a\u306b\u30e1\u30e2\u30ea\u3092\u6c17\u306b\u3057\u306a\u304f\u3066\u3082\u3088\u3044\u306e\u3067\u3001\u6539\u3081\u3066\u7d44\u3093\u3067\u307f\u3088\u3046\u3002<br \/>\n\u4e0a\u306e\u30d1\u30bf\u30fc\u30f3\u306f\u6761\u4ef6\u5224\u5b9a\u3092\u4f55\u5ea6\u3082\u547c\u3076\u3053\u3068\u306b\u306a\u308b\u306e\u3067\u5c11\u3057\u5de5\u592b\u3057\u3066<\/p>\n<pre>\r\nfunction Move (n, from, to , using) =\r\n if n=1 \"Move a Disk from 'from' to 'to'\"\r\nelse\r\n Move (n-1,from, using,to)\r\n \"Move a Disk from 'from' to 'to'\"\r\n Move (n-1,using, to, from)\r\n<\/pre>\n<p>\u3068\u3044\u3046\u3088\u3046\u306a\u30ed\u30b8\u30c3\u30af\u3092\u4f7f\u3046\u3053\u3068\u3068\u3057\u3001<br \/>\nFree Pascal\u3067\u66f8\u3044\u305f\u4f8b<br \/>\n<code><\/p>\n<pre>\r\nprogram hanoi;\r\n             {Recursively solve the towers of Hanoi problem.  Moves disks from A to C.\r\n             The code from \"Oh Pascal\" by Doug Cooper}\r\nvar height:integer;\r\n  procedure Move (Height: integer; FromPeg,ToPeg,UsingPeg:char);\r\n  begin\r\n    if Height = 1\r\n    then writeln('Move disk from ', FromPeg,' to ',ToPeg)\r\n    else begin\r\n      Move (Height-1, FromPeg,UsingPeg,ToPeg);\r\n      writeln('Move a disk from ',FromPeg,' to ',ToPeg);\r\n      Move (Height-1,UsingPeg,ToPeg,FromPeg)\r\n    end;\r\n  end;\r\n\r\nbegin\r\n  writeln('How Many disks are you going to start with?');\r\n  readln(Height);\r\n  Move (Height,'A','C','B');\r\n  readln()\r\nend.\r\n<\/pre>\n<p><\/code>       <\/p>\n<p>C++\u3067\u66f8\u3044\u305f\u4f8b<\/p>\n<pre>\r\n#include < iostream >\r\n\r\nusing namespace std;\r\nvoid move(int numberOfDisk, char fromPin,char toPin,char usePin);\r\n\r\n\r\nint main() {\r\n    int numberOfDisk;\r\n    char fromPin = 'A',usePin='B',toPin='C';\r\n    cout << \"How many disk do you want to move from pin A to pin C?: \" ;\r\n    cin >> numberOfDisk;\r\n    move (numberOfDisk,fromPin,toPin,usePin);\r\n\r\n    return 0;\r\n}\r\nvoid move(int numberOfDisk, char fromPin,char toPin,char usePin) {\r\n    if(numberOfDisk == 1) cout << \"Move a Disk from \"<< fromPin << \" to \" << toPin<< endl;\r\n    else {\r\n        move(numberOfDisk-1,fromPin,usePin,toPin);\r\n        cout << \"Move a Disk from \" << fromPin << \" to \" << toPin << endl;\r\n        move(numberOfDisk-1,usePin,toPin,fromPin);\r\n    }\r\n\r\n}\r\n<\/pre>\n<p>Python\u3067\u66f8\u3044\u305f\u4f8b<\/p>\n<p><code><\/p>\n<pre>\r\n'''Towers of Hanoi'''\r\ndef move(numberOfDisk, fromPin, toPin, usingPin):\r\n    if (numberOfDisk == 1):\r\n        print (\"Move a Disk from \",fromPin,\" to \",toPin)\r\n    else:\r\n        move(numberOfDisk-1,fromPin,usingPin,toPin)\r\n        print (\"Move a Disk from \",fromPin,\" to \",toPin)\r\n        move(numberOfDisk-1,usingPin,toPin,fromPin)\r\n\r\nif __name__ == '__main__':\r\n    numberOfDisk = input(\"How many Disk would you like to move? \")\r\n    move(int(numberOfDisk),'A','B','C')\r\n<\/pre>\n<p><\/code><br \/>\nPython \u3067\u5186\u76e4\u306e\u6570\u30924\u3068\u3057\u305f\u5834\u5408\u306e\u5b9f\u884c\u4f8b<\/p>\n<pre><code>\r\n~ $ python3 hanoi.py\r\nHow many Disk would you like to move? 4\r\nMove a Disk from  A  to  C\r\nMove a Disk from  A  to  B\r\nMove a Disk from  C  to  B\r\nMove a Disk from  A  to  C\r\nMove a Disk from  B  to  A\r\nMove a Disk from  B  to  C\r\nMove a Disk from  A  to  C\r\nMove a Disk from  A  to  B\r\nMove a Disk from  C  to  B\r\nMove a Disk from  C  to  A\r\nMove a Disk from  B  to  A\r\nMove a Disk from  C  to  B\r\nMove a Disk from  A  to  C\r\nMove a Disk from  A  to  B\r\nMove a Disk from  C  to  B\r\n<\/code><\/pre>\n<p>\u52d5\u304b\u3059\u56de\u6570\u306f\u5186\u76e4\u306e\u6570\u304c1\u306e\u6642\u306f1\u30012\u306e\u6642\u306f3\u30013\u306e\u6642\u306f7\u30014\u306e\u6642\u306f\u4e0a\u306e\u51fa\u529b\u306e\u3088\u3046\u306b15\u3068\u306a\u308a\u3001\u5186\u76e4\u306e\u6570\u304c\uff4e\u306e\u3068\u304d\u306f<\/p>\n<pre>\r\n2\u306e\uff4e\u4e57\u304b\u3089\uff11\u3092\u5f15\u3044\u305f\u5024\r\n<\/pre>\n<p>\u3068\u306a\u308b\u3002\u679a\u6570\u304c\u591a\u3051\u308c\u3070\u591a\u3044\u307b\u3069\u5168\u90e8\u306e\u30b9\u30c6\u30c3\u30d7\u306e\u6570\u304c\u3069\u3093\u3069\u3093\u5927\u304d\u304f\u306a\u3063\u3066\u3044\u304f\u3002<br \/>\nPython version \u3067\u8a66\u3057\u3066\u307f\u308b\u3068\u3001\u624b\u6301\u3061\u306e\u3084\u3084\u304f\u305f\u3073\u308c\u305f\u30ce\u30fc\u30c8\u30d6\u30c3\u30af\u30d1\u30bd\u30b3\u30f3\u3067\u306f\u30b9\u30c6\u30c3\u30d7\u306e\u51fa\u529b\u304c\u7d42\u308f\u308b\u306e\u306b\u3000\u5186\u76e4\u306e\u6570\u304c23\u679a\u306730\u79d2\u300124\u679a\u30671\u5206\u300125\u679a\u30672\u5206\u304b\u304b\u3063\u305f\u3002\uff08\u4e0b\u306e\u51fa\u529b\u7d50\u679c\u53c2\u7167\uff09\u5b9f\u884c\u6642\u9593\u304c\u3053\u3053\u306e\u8abf\u5b50\u3067\u500d\u3005\u3067\u5897\u3048\u3066\u3044\u304f\u3068\u3059\u308b\u3068\u5165\u529b\u304c64\u679a\u306e\u3068\u304d\u306b\u89e3\u6cd5\u3092\u51fa\u529b\u3059\u308b\u306e\u306b2\u306e38\u4e57\u306e\u5206\u304c\u304b\u304b\u308b\u3068\u3044\u3046\u3053\u3068\u306b\u306a\u308b\u304c\u3001\u3053\u308c\u3092\u5e74\u306b\u76f4\u3059\u3068\u3001\u306a\u3093\u306852\u4e07\u5e74\u3068\u3044\u3046\u3068\u3093\u3067\u3082\u306a\u3044\u6570\u5b57\u306b\u306a\u308b\u3002\u3000\u306e\u3067\u4e0a\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u306b64\u3068\u5165\u529b\u3057\u3088\u3046\u3082\u306e\u306a\u3089\u8a08\u7b97\u304c\u7d42\u308f\u3089\u306a\u3044\u3002\u3000\u306a\u308b\u307b\u3069\u3001\u3053\u308c\u3067\u306f\u4e16\u754c\u304c\u6ec5\u3073\u308b\u308f\u3051\u3060\u3002<br \/>\n<code><\/p>\n<pre>\r\n~ $ time echo 23 | python3 hanoi.py >\/dev\/null\r\nreal\t0m29.308s\r\nuser\t0m29.225s\r\nsys\t0m0.054s\r\n~ $ time echo 24 | python3 hanoi.py>\/dev\/null\r\nreal\t0m58.437s\r\nuser\t0m58.237s\r\nsys\t0m0.122s\r\n~ $ time echo 25 | python3 hanoi.py>\/dev\/null\r\nreal\t1m55.068s\r\nuser\t1m54.540s\r\nsys\t0m0.320s\r\n\r\n<\/pre>\n<p><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30cf\u30ce\u30a4\u306e\u5854\u3068\u3044\u3046\u306e\u306f\u30d1\u30ba\u30eb\u3060\u304c\u3001\u30ea\u30ab\u30fc\u30b8\u30e7\u30f3\u3068\u3044\u3046\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u306b\u3088\u304f\u306a\u3058\u3080\u306e\u3067\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306e\u6559\u79d1\u66f8\u306b\u51fa\u3066\u3044\u308b\u3053\u3068\u304c\u3042\u308b\u3002\u3000\u81ea\u5206\u304c\u3053\u308c\u3092\u898b\u305f\u306e\u306f&#8221;Oh Pascal!&#8221;\u3068\u3044\u3046\u30d1\u30b9\u30ab\u30eb\u306e\u5165\u9580\u66f8\u306730\u5e74\u304f\u3089\u3044\u524d\u306b\u767a\u884c\u3055\u308c\u305f\u5b66\u751f\u5411\u3051\u306e\u6559\u79d1\u66f8\u3060\u3002 \u30d1\u30ba\u30eb\u306e\u5185\u5bb9\u306f\u3053\u3093\u306a\u5177\u5408\u3002 \uff11\uff0e3\u672c\u306e\u68d2\u304c\u7acb\u3063\u3066\u3044\u308b\u3002\u4eee\u306b\u3053\u308c\u3092\u53f3\u304b\u3089A,B,C\u3068\u3059\u308b\u3002 \uff12\uff0eA\u306b\u306f\u771f\u3093\u4e2d\u306b\u7a74\u306e\u3042\u3044\u305f\u5186\u76e4\u304c\u7a4d\u307f\u4e0a\u3052\u3066\u3042\u308b\u3002\u5186\u76e4\u306e\u76f4\u5f84\u306f\u5e95\u306b\u3042\u308b\u3082\u306e\u304c\u4e00\u756a\u5927\u304d\u304f\u3001\u4e0a\u306b\u884c\u304f\u307b\u3069\u5c0f\u3055\u304f\u306a\u308b\u3002 \uff13\uff0e\u4e00\u5ea6\u306b\u4e00\u500b\u305a\u3064\u3053\u306e\u3053\u306e\u5186\u76e4\u3092\u53d6\u308a\u51fa\u3057\u3066\u4ed6\u306e\u68d2\u306b\u79fb\u3059\u3053\u3068\u304c\u3067\u304d\u308b\u3002\u6700\u7d42\u7684\u306b\u306f\u5168\u90e8\u306e\u5186\u76e4\u3092C\u306b\u79fb\u3057\u305f\u3044\u3002 \uff14\uff0e\u305f\u3060\u3057\u3001\u5927\u304d\u306a\u5186\u76e4\u3092\u5c0f\u3055\u306a\u5186\u76e4\u306e\u4e0a\u306b\u7f6e\u304f\u3053\u3068\u306f\u3067\u304d\u306a\u3044\u3002 Hanoi\u306e\u5854\u3068\u3044\u3046\u306e\u306f\u3053\u306e\u201d\u91d1\u306e\u201d\u5186\u76e4\u309264\u679a\u7a4d\u307f\u4e0a\u3052\u305f\u3082\u306e\u3060\u305d\u3046\u3067\u3001\u3053\u306e\u30d1\u30ba\u30eb\u304c\u89e3\u3051\u305f\u3068\u304d\u306b\u306f\u4e16\u306e\u4e2d\u304c\u7d42\u7109\u3092\u8fce\u3048\u308b\u3001\u3068\u3044\u3046\u30aa\u30c8\u30ed\u3057\u3044\u843d\u3061\u304c\u3064\u3044\u3066\u3044\u308b\u3002 \u3053\u308c\u3092\u30b3\u30f3\u30d4\u30e5\u30fc\u30bf\u30fc\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4f7f\u3063\u3066\u89e3\u304f\u3068\u3069\u3046\u306a\u308b\u304b\u3001\u3068\u3044\u3046\u8a71\u3067\u3042\u308b\u3002\u3000\u30d1\u30bf\u30fc\u30f3\u3092\u898b\u3064\u3051\u308b\u305f\u3081\u306b\u5c11\u306a\u3044\u679a\u6570\u3067\u5b9f\u969b\u306b\u89e3\u304f\u3053\u3068\u3092\u8a66\u307f\u308b\u3002 Disk(\u5186\u76e4\uff09\u306e\u6570\u304c\u4e00\u679a\u306e\u6642\u306b\u306f\u7c21\u5358\u3060\u3002\u5186\u76e4\u3092A\u304b\u3089C\u306b\u79fb\u305b\u3070\u3088\u3044\u3002 Move(1disk from A to C) =\u3000Move a Disk from A to C \u3067\u306f2\u679a\u306e\u6642\u306b\u306f\u3069\u3046\u306a\u308b\u304b Move(2disks from A to C) = Move a Disk from A to B Move a Disk from A to C Move a Disk from B to C \u3053\u3053\u3067\u68d2B\u3092\u4f7f\u3046\u3053\u3068\u306b\u306a\u308b\u3002\u3000\u3064\u307e\u308a\u3001\u307e\u305a\u4e0a\u306e\u5186\u76e4\u3092\u68d2A\u304b\u3089B\u306b\u79fb\u3057\u3001\u4e0b\u306e\u5186\u76e4\u3092A\u304b\u3089C\u3078\u3001\u6700\u5f8c\u306bB\u306b\u79fb\u3057\u3066\u3042\u3063\u305f\u5186\u76e4\u3092C\u306b\u79fb\u3057\u3066\u5b8c\u6210\u3060\u3002 Move (2 disks from A to C)\u3000= Move (2 disks from A to C using B) 3\u679a\u306f\u3069\u3046\u304b\u3002\u3000\u3059\u3067\u306b2\u679a\u3092\u52d5\u304b\u3059\u65b9\u6cd5\u306f\u308f\u304b\u3063\u3066\u3044\u308b\u306e\u305d\u306e\u65b9\u6cd5\u3092\u4f7f\u3063\u3066\u307e\u305a\u306f2\u679a\u3092B\u306b\u52d5\u304b\u3057\u3066\u304a\u304d\u3001\u6700\u5f8c\u306e\u4e00\u679a\u3092A\u304b\u3089C\u306b\u79fb\u52d5\u3001\u3055\u3089\u306b2\u679a\u3092\u52d5\u304b\u3059\u65b9\u6cd5\u3092\u4f7f\u3063\u3066B\u304b\u3089C\u306b\u79fb\u52d5\u3059\u308b\u3068\u3044\u3046\u65b9\u6cd5\u3067\u52d5\u304b\u305b\u308b\u3002 Move(3 disks from A to C using B)\u3000= Move(2 disks from A to B using C) Move a disk from A to C Move (2 disks from B to c using A) 4\u679a\u306e\u5834\u5408\u3082\u540c\u69d8\u306b\u8003\u3048\u3089\u308c\u308b\u306e\u3067\u30d1\u30bf\u30fc\u30f3\u3068\u3057\u3066\u306f\u3000(n-1)\u679a\u306e\u5186\u76e4\u3092A\u304b\u3089B\u306b\u79fb\u3059\u3002\u6700\u5f8c\u306e\u5186\u76e4\u3092A\u304b\u3089C\u306b\u79fb\u52d5\u3057\u3001\u305d\u306e\u5f8c(n-1)\u679a\u306e\u5186\u76e4\u3092B\u304b\u3089C\u306b\u79fb\u3059\u3002\u3000\u3068\u3044\u3046\u3053\u3068\u306b\u306a\u308b\u3002 Move (n disks from A to C using B) &hellip; <a href=\"https:\/\/www.a2life.info\/w\/?p=1574\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[45,53,52,41,49],"class_list":["post-1574","post","type-post","status-publish","format-standard","hentry","category-18","tag-c","tag-pascal","tag-programming-2","tag-python","tag-python3"],"_links":{"self":[{"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=\/wp\/v2\/posts\/1574","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1574"}],"version-history":[{"count":20,"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=\/wp\/v2\/posts\/1574\/revisions"}],"predecessor-version":[{"id":1596,"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=\/wp\/v2\/posts\/1574\/revisions\/1596"}],"wp:attachment":[{"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1574"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1574"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1574"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}