ãªãã¨ãªã5æ¥ã空ãã¦ããã®ã§æ¸ãã¦ã¿ã¾ãã
ãã®ã¨ã³ããªã¯ ãã¼ãã§ã¯ãRuby Advent Calendar ã®5æ¥ç®ã®ã¨ã³ããªã§ãã åã®æ¥ã®ã¨ã³ããªã¯ http://d.hatena.ne.jp/zonu_exe/20131204/1386271407 ã§ãã*1ã
ãã¼ãã§ã¯ãRuby (PERFECT SERIES 6)
- ä½è : Rubyãµãã¼ã¿ã¼ãº,ããããã¾ãã®ã,寺ç°ç太é,ä¸æçé,è¿è¤å®æºæ,æ©ç«åå®,é¢å£äº®ä¸
- åºç社/ã¡ã¼ã«ã¼: æè¡è©è«ç¤¾
- çºå£²æ¥: 2013/08/10
- ã¡ãã£ã¢: 大åæ¬
- ãã®ååãå«ãããã° (9件) ãè¦ã
ãã¼ãã§ã¯ãRubyã«è¼ã£ã¦ããªã便å©ã¯ã©ã¹
ãã¼ãã§ã¯ãRubyã§çµã¿è¾¼ã¿ã¯ã©ã¹ãæ¨æºæ·»ä»ã©ã¤ãã©ãªçã説æãã¦ãã¾ããã¨ã¯ãããå ¨ã¦ãç¶²ç¾ ãã¦ããããã§ã¯ããã¾ããã ãããªæ¼ãã¦ããã¯ã©ã¹ã®ãªãã§ããã«å¾æ å ±ã¨ãã¦åé«ãï¼ã¨åæã«æã£ã¦ããï¼ã¯ã©ã¹ã¨ãã¦TSortãããã¾ãã
ãã®TSortã¯ä¾åé¢ä¿ãã¤ã¤ã«ã³ã¸ã«è§£æ±ºãã¦ããããããã¸ã«ã«ã½ã¼ãã£ã¦ããã®ãæä¾ãã¦ãããã
require 'tsort' class Hash include TSort alias tsort_each_node each_key def tsort_each_child(node, &block) fetch(node).each(&block) end end {1=>[2, 3], 2=>[3], 3=>[], 4=>[]}.tsort #=> [3, 2, 1, 4]
ä¾åã¨ããè¨èã使ã£ã¦ãããã©ãä½ç½®ã¨ãè·é¢ã£ã¦è¨ã£ãã»ããæ£ããæ°ãããã tsortã¡ã½ããå®è¡ããçµæãè¦ãã¨ããããããããªãããã©ã3ã¨ããã®ã¯1ã¨2ããåç §ããã¦ããã®ã§ãå é ã«ä¸¦ã³æ¿ãããããåãããã«ã1ã¯2ã¨3ãåç §ãã¦ãããã®ã§ã2ãããå¾ã«æ¥ãã¨ããæããè¨èã§èª¬æããã®ãããããã§ããã
å®ã¯
ãããç¥ã£ã風ã«ç´¹ä»ãã¾ãããã©ãainameããã®ã¨ã³ã㪠ã§ç¥ã£ãã ãã§ãããã¼ãã¯ããã¾ã§ãã®ã¯ã©ã¹ãç¥ãã¾ããã§ãããã©ããªãã¨ãªãç¥ã£ã¦ããã¨å©ããå¯è½æ§ãå¾®ã¬åãªæ°ãããã®ã§ã使ãæ¹ãè¦ãã¦ããã¦æã¯ããªããã ã¨æã£ã¦ã¾ãã
次ã®ã¢ããã³ã¿ã¼ã¯
ãã¼ãã§ã¯ãRubyå·çè ã§ããã id:joker1007 ããã§ããã©ããªã¨ã³ããªã«ãªãã®ãã楽ãã¿ã§ããã
*1:12/4ã®ã¨ã³ããªãæ¸ããããããªã®ã§ä¿®æ£ãã¾ãã