Rubyãã¹ããã©ã¯ãã£ã¹ã®5-4ããï¼ã¡ã¿ããã°ã©ãã³ã°ã®ä¾ã¨ãã¦é¢ç½ãã£ãã®ã§ã¾ã¨ãã¦ã¿ãï¼ ã¡ã¢åã¨ã¯ ã¡ã¢åã¨ã¯ï¼å¼æ°ã«å¯¾ããã¡ã½ããã®æ»ãå¤ãä¿åãã¦ããï¼åã³åãå¼æ°ã§ã¡ã½ãããå¼ã³åºãããæã«ãã®å¤ãåå©ç¨ãããã¨ã«ããï¼åãè¨ç®ãä½åº¦ããããã¨ãé²ãæé©åææ³ã®ã²ã¨ã¤ï¼å
¨ã¦ã®å¼æ°ã«å¯¾ãã¡ã½ããã®çµæãä¸å¤ã®å ´å(åãå¼æ°ã§ä½åº¦å¼ã³åºãã¦ãæ¯ååãæ»ãå¤ãè¿ãå ´å)ï¼ã¡ã½ãããã¡ã¢åãããã¨ãã§ããï¼ ä»¥ä¸ã¯ãã£ããããæ°ãå帰ã§è¨ç®ããã¡ã½ããfibã®ä¾ï¼ def fib(n) (0..1).include?(n) ? n : fib(n-2) + fib(n-1); end ãã®å®è£
ã®å ´åï¼ä¾ãã°fib(n)ã¯n = 3ã§5åï¼n = 4ã§9åã¨ããããã«ï¼nã®å¤ã大ãããªãã«ã¤ãã¦å帰å¼ã³åºãåæ°ãã©ãã©ãå¢ãï¼å®è¡æéãççºçã«å¢å¤§ãã¦ãã¾ãï¼ç§ã®ç°å¢ã ã¨fib(30
{{#tags}}- {{label}}
{{/tags}}