{"id":217,"date":"2010-04-02T00:04:18","date_gmt":"2010-04-01T15:04:18","guid":{"rendered":"http:\/\/www.typea.info\/blog\/index.php\/2010\/04\/02\/_11\/"},"modified":"2010-04-02T00:04:18","modified_gmt":"2010-04-01T15:04:18","slug":"_11","status":"publish","type":"post","link":"https:\/\/www.typea.info\/blog\/index.php\/2010\/04\/02\/_11\/","title":{"rendered":"\u4e00\u4eba\u8aad\u66f8\u4f1a \u300c\u8a08\u7b97\u6a5f\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u69cb\u9020\u3068\u89e3\u91c8\u300d (11)"},"content":{"rendered":"<p><a href=\"http:\/\/www.amazon.co.jp\/dp\/489471163X?tag=typea09-22&amp;link_code=as3&amp;creativeASIN=489471163X&amp;creative=3999&amp;camp=767\"><img decoding=\"async\" src=\"http:\/\/images-jp.amazon.com\/images\/P\/489471163X.09.MZZZZZZZ.jpg\" complete=\"complete\"><\/a> <\/p>\n<p>&nbsp;<\/p>\n<h2>1.2.1\u3000\u7dda\u5f62\u518d\u5e30\u3068\u53cd\u5fa9<\/h2>\n<h3>\u518d\u5e30\u7684\u30d7\u30ed\u30bb\u30b9(recursive process) <\/h3>\n<p>\u4efb\u610f\u306e\u6b63\u306e\u6574\u6570 n \u306b\u5bfe\u3059\u308b\u968e\u4e57\u95a2\u6570 n! \u306f\u3001 n \u30fb (n-1)! \u3067\u5f97\u3089\u308c\u308b\u3002\u3064\u307e\u308a\u3001n! \u306f\u3001 (n-1)!&nbsp; \u3092\u8a08\u7b97\u3057\u3001\u7d50\u679c\u306b n \u3092\u304b\u3051\u3066\u8a08\u7b97\u3067\u304d\u308b\u30021! \u306f 1\u306b\u7b49\u3057\u3044\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u624b\u7d9a\u304d\u306b\u5909\u63db\u3067\u304d\u308b\u3002<\/p>\n<pre class=\"prettyprint linenums\">(define (factorial n)\r\n  (if (= n 1)\r\n      1\r\n      (* n (factorial (- n 1)))))\r\n<\/pre>\n<p>\u3053\u306e\u5f62\u306e\u30d7\u30ed\u30bb\u30b9\u3092<strong>\u518d\u5e30\u7684\u30d7\u30ed\u30bb\u30b9(recursive process)<\/strong> \u3068\u3044\u3044\u3001<strong>\u9045\u5ef6\u6f14\u7b97(deferred operations) <\/strong>\u306e\u5217\u3067\u7279\u5fb4\u3065\u3051\u3089\u308c\u308b\u3002<\/p>\n<p>\u9045\u5ef6\u6f14\u7b97\u3068\u306f\u3001\u30d7\u30ed\u30bb\u30b9\u304c\u81a8\u5f35\u3068\u53ce\u7e2e\u306e\u5f62\u3092\u3068\u308b\u3068\u304d\u3001\u81a8\u5f35\u6642\u306b\u9045\u5ef6\u6f14\u7b97\u306e\u5217\u3068\u3057\u3066\u4f5c\u6210\u3055\u308c\u308b\u3002\u53ce\u7e2e\u306f\u6f14\u7b97\u304c\u5b9f\u969b\u306b\u5b9f\u884c\u3055\u308c\u308b\u6642\u306b\u8d77\u304d\u308b\u3002<\/p>\n<p>\u89e3\u91c8\u7cfb\u306f\u3001\u5f8c\u306b\u5b9f\u884c\u3059\u308b\u6f14\u7b97\u3092\u899a\u3048\u3066\u304a\u304f\u5fc5\u8981\u304c\u3042\u308a\u3001\u899a\u3048\u3066\u304a\u304f\u5fc5\u8981\u306e\u3042\u308b\u60c5\u5831\u91cf\u306f n \u306b\u6bd4\u4f8b\u3057\u3066(\u7dda\u5f62\u306b)\u6210\u9577\u3059\u308b\u305f\u3081\u3001\u3053\u3046\u3044\u3046\u30d7\u30ed\u30bb\u30b9\u3092<strong>\u7dda\u5f62\u518d\u5e30\u7684\u30d7\u30ed\u30bb\u30b9(liner recuresive porceee) <\/strong>\u3068\u3044\u3046\u3002<\/p>\n<p>\u4f8b\u306b\u3088\u3063\u3066\u3001Scheme\u3067\u306f\u3001\u305d\u306e\u69d8\u5b50\u3092\u78ba\u8a8d\u3059\u308b\u3060\u3051\u306e\u30b9\u30ad\u30eb\u304c\u307e\u3060\u7121\u3044\u306e\u3067\u3001\u305f\u307e\u306b\u306f Java \u3067\u78ba\u8a8d\u3057\u3066\u307f\u308b\u3002<\/p>\n<p>\u3084\u3063\u3066\u3044\u308b\u3053\u3068\u306e\u3001\u672c\u8cea\u7684\u306b\u306f\u3001\u3053\u308c\u3060\u3051\u306e\u3053\u3068\u3002<\/p>\n<pre class=\"prettyprint linenums\">private long factorial(long num){\r\npackage cap1_2_1;\r\n\r\npublic class Capter1_2_1 {\r\n\tpublic long factorial(long num){\r\n\t\tif (num == 1L){\r\n\t\t\treturn 1L;\r\n\t\t}\r\n\t\treturn num * this.factorial(num - 1L);\r\n\t}\r\n}\r\n<\/pre>\n<p>\u51e6\u7406\u306e\u7d4c\u904e\u3092\u30c8\u30ec\u30fc\u30b9\u3059\u308b\u305f\u3081\u306b\u3001\u3044\u308d\u3044\u308d\u3068\u7d44\u307f\u8fbc\u307f\u3001\u5f15\u6570\u306b 8 \u3092\u4e0e\u3048\u3066\u5b9f\u884c\u3057\u3066\u307f\u308b\u3002<\/p>\n<pre class=\"prettyprint linenums\">package cap1_2_1;\r\n\r\nimport java.util.Stack;\r\n\r\npublic class Capter1_2_1 {\r\n\t\/\/ \u30c8\u30ec\u30fc\u30b9\u7528\r\n\tprivate Stack<string> stk = new Stack<string>();\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tCapter1_2_1 me = new Capter1_2_1();\r\n\t\tlong num = Long.parseLong(args[0]);\r\n\t\tme.testFactorial(num);\r\n\t}\r\n\tpublic void testFactorial(long num){\r\n\t\tstk.push(String.format(\"factional(%d)\", num));\r\n\t\tlong result = this.factorial(num);\r\n\t\tSystem.out.printf(\"*************\\n\");\r\n\t\tSystem.out.printf(\"%d! = %d\\n\", num, result);\r\n\t}\r\n\tpublic long factorial(long num){\r\n\t\tSystem.out.println(stk.toString());\r\n\t\tstk.pop();\r\n\t\tstk.push(String.format(\"%d\", num));\r\n\t\t\r\n\t\tif (num == 1L){\r\n\t\t\tSystem.out.println(stk.toString());\r\n\t\t\treturn 1L;\r\n\t\t}\r\n\t\t\r\n\t\tstk.push(String.format(\"factorial(%d)\", num - 1L));\r\n\t\tlong num_minus_1 = this.factorial(num - 1L);\r\n\t\t\r\n\t\tstk.pop(); \/\/ \u81ea\u8eab\r\n\t\tstk.pop(); \/\/ \u3072\u3068\u3064\u624b\u524d\u3092\u8a08\u7b97\u7d50\u679c\u306b\u7f6e\u304d\u63db\u3048\r\n\t\tstk.push(String.format(\"%d\", num * num_minus_1));\r\n\t\t\r\n\t\tSystem.out.println(stk.toString());\r\n\t\treturn num * num_minus_1;\r\n\t}\r\n}\r\n<\/pre>\n<p>\u81a8\u5f35\u3068\u3001\u53ce\u7e2e\u306e\u69d8\u5b50\u304c\u3088\u304f\u5206\u304b\u308b\u3002<\/p>\n<pre class=\"prettyprint linenums\">[factional(8)]\r\n[8, factorial(7)]\r\n[8, 7, factorial(6)]\r\n[8, 7, 6, factorial(5)]\r\n[8, 7, 6, 5, factorial(4)]\r\n[8, 7, 6, 5, 4, factorial(3)]\r\n[8, 7, 6, 5, 4, 3, factorial(2)]\r\n[8, 7, 6, 5, 4, 3, 2, factorial(1)]\r\n[8, 7, 6, 5, 4, 3, 2, 1]\r\n[8, 7, 6, 5, 4, 3, 2]\r\n[8, 7, 6, 5, 4, 6]\r\n[8, 7, 6, 5, 24]\r\n[8, 7, 6, 120]\r\n[8, 7, 720]\r\n[8, 5040]\r\n[40320]\r\n*************\r\n8! = 40320\r\n<\/pre>\n<p>Java \u597d\u304d\u3060\u3057\u3001\u304a\u3082\u3057\u308d\u3044\u3051\u3069\u3001\u3084\u306f\u308aPython \u3068\u6bd4\u3079\u308b\u3068\u3001\u601d\u8003\u304b\u3089\u5b9f\u88c5\u307e\u3067\u306e\u30e9\u30b0\u304c\u3061\u3087\u3063\u3068\u5927\u304d\u3044\u306a\u3041~<\/p>\n<p>\u4eca\u65e5\u306f\u3053\u3053\u307e\u3067\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; 1.2.1\u3000\u7dda\u5f62\u518d\u5e30\u3068\u53cd\u5fa9 \u518d\u5e30\u7684\u30d7\u30ed\u30bb\u30b9(recursive process) \u4efb\u610f\u306e\u6b63\u306e\u6574\u6570 n \u306b\u5bfe\u3059\u308b\u968e\u4e57\u95a2\u6570 n! \u306f\u3001 n \u30fb (n-1)! \u3067\u5f97\u3089\u308c\u308b\u3002\u3064\u307e\u308a\u3001n! \u306f\u3001 (n-1)!&#038;nbs [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"sns_share_botton_hide":"","vkExUnit_sns_title":"","_vk_print_noindex":"","sitemap_hide":"","_veu_custom_css":"","veu_display_promotion_alert":"","vkexunit_cta_each_option":"","footnotes":""},"categories":[33,20,34,35,36],"tags":[],"class_list":["post-217","post","type-post","status-publish","format-standard","hentry","category-lisp","category-python","category-scheme","category-math","category-reading"],"veu_head_title_object":{"title":"","add_site_title":""},"_links":{"self":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/217","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=217"}],"version-history":[{"count":0,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/posts\/217\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=217"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=217"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.typea.info\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}