2007-10-01から1ヶ月間の記事一覧

八本目 さいころ

p rand(6)+1

七本目 appleにはマッチするけどgreen appleにはマッチしない置換(失敗)

str =####ここから %Q{this green apple is an apple but is not an green apple }###ここまで matchword = "apple" notmatchword = "green apple" str.each do |line| word = line while /apple/ =~ word do if word.index(/#{notmatchword}/) + notmatchwo…

六本目 CSV分解

str =####ここから %Q{one, two, three, four }###ここまで str.each do |line| ary = line.split(",") ary.each do |word| print word.strip print "\n" end end

五本目 四本目の逆

str =####ここから %Q{HELLO_WORLD THIS_IS_TEST_PATTERN TEST_METHOD }###ここまで str.each do |line| word = line while /[A-Z]*_/ =~ word do print $&.capitalize.chop word = $' end print word.capitalize.chomp print "\n" end

四本目 HelloHellWorld→HELLO_HELL_WORLD

str =####ここから %Q{HelloWorld ThisIsTestPattern TestMethod }###ここまで str.each do |line| word = line /[A-Z][a-z]*/ =~ word while /[A-Z][a-z]*/ =~ word do print $&.upcase! if $'.chomp.length > 0 then print '_' end word = $' end print "\…

三本目 ダブルクオートで囲まれた数字に+1

str =####ここから %Q{HashMap map = new HashMap(); map.put("0", "zero"); map.put("1", "one"); map.put("2", "two"); map.put("3", "three"); map.put("10", "ten"); }###ここまで str.each do |line| if /"[0-9]*"/ =~ line then print $` num = $&[1..…

二本目 メソッド生成

str = ####ここから "getParentWindow getParentFrame init " ###ここまで str.each do |line| print "public void "+line.chomp+"(){ //TODO } " end

一本目 ひながた(貼り付けたテキストをそのまま表示)

str = #↓↓↓↓ここから " getParentWindow getParentFrame init testPattern1 testPattern2 " #↑↑↑↑ここまで str.each do |line| print line end

十本目 あいさつ

print "Hello, warld"

九本目 さいころ一万回ふる

a = Array.new(10000) normdist = 0.0 max = 0.0 include Math for i in 1..10000 a[i] = rand(6)+1 max += a[i] end ave = max / 10000 print "平均:"+ ave.to_s for i in 1..10000 normdist += (a[i] - ave) * (a[i] - ave) end normdist = sqrt(normdist…

Ruby10本ノック

仕事に反復作業が多くてとても悲しい ので、モチベ維持&効率化のためにRubyを少しずつ勉強中 でもすぐ忘れる100本ノックにしたいとこだが、どうせ続かないので10本くらい目標。

TSSCPとの違い

はてなMMLではループを抜けた時、オクターブが戻らないので、 TSSCPで作るときは[]で繰り返した方がいいかも

long goodbye作業用長いバージョン

$Melo = @E1,30,80,20,0/:2o6 a-4>b<g-e-4r>bb-4ba-b-b<d-/ee-4re-d-c>a-e-:/>b-a-4a-<e-d-c>a-e-; $Arp = o3 eb<eg-a-rrr> eb<e>eg-<d-g->g- a-<e-b-<ce->a->a-</e-b-<ce-></d-g-></e></eg-a-rrr></e-d-c></d-/ee-4re-d-c></g-e-4r>

聖剣伝説 long goodbye

$Melo = @E1,30,80,20,0/:2o6 a-4>b<g-e-4r>bb-4ba-b-b<d-/ee-4re-d-c>a-e-:/>b-a-4a-<e-d-c>a-e-; $Arp = o3 eb<eg-a-rrr> eb<e>eg-<d-g->g- a-<e-b-<ce->a->a-</e-b-<ce-></d-g-></e></eg-a-rrr></e-d-c></d-/ee-4re-d-c></g-e-4r>

こうですか

リズムのみ $BD=@0@e1,0,35,0,0 v15o2; $BA=@0@e1,0,4,0,0 v15o3; $SD=@4@e1,0,30,0,0@n110v10; $SA=@2@e1,0,15,0,0 v15o3; $HH=@4@e1,0,13,0,0@n20v10; t130 /:4 $SDrcrcrcrc8r12c24 :/; t130 /:8 $SArcrc :/; t130 /:8 $BDo2gr8g8gg :/; t130 /:8 $BDo2gr8…