2007-07-03
■ 差集合

Rubyの場合、集合A-集合Bと書くことによって簡単に差集合を求めることが出来ます。
サンプルコード
# # difference_set.rb # langs = ["Python", "C", "Ruby", "Java", "Perl", "PHP", "C#" ,"C++"] not_light_weight_langs = ["C", "Java", "C#", "C++"] #langsとnot_light_weight_langsの差集合を求めている。 lightWeight_langs = langs - not_light_weight_langs #上で求めた差集合の結果を、シングルクォートでjoinして、",PHP$"にマッチするものを" and PHP"で置換した結果を標準出力 puts "#{lightWeight_langs.join(',').sub(/,PHP/, ' and PHP')} are called LightWeight Language."
実行結果
Python,Ruby,Perl and PHP are called LightWeight Language.
コメントを書く
Frenchy2011/09/09 02:36Thank you so much for this atricle, it saved me time!
rwucpnv2011/09/09 16:50n6tQMb <a href="http://lplfdgfnmkrg.com/">lplfdgfnmkrg</a>
qpqsae2011/09/10 17:581w5scn , [url=http://djynmnqanisd.com/]djynmnqanisd[/url], [link=http://bclondtnvkay.com/]bclondtnvkay[/link], http://tyikvadicvwr.com/
rcjgkknps2011/09/11 23:12cgea7A <a href="http://ihyyfofljtae.com/">ihyyfofljtae</a>
nvcuqp2011/09/12 21:02yE44Fg , [url=http://rwbcpraupbsi.com/]rwbcpraupbsi[/url], [link=http://rrxtyycgzdvc.com/]rrxtyycgzdvc[/link], http://dekkmlhosbmq.com/