サイログ。

~雑多な記事置き場~

初心者教室回答例


1.世界のナベアツ

みんな流行に乗りすぎです(ミクとかにはまってるヤツが言うなって?)

1.upto(100){|n|
  str = (n % 3 == 0 || n.to_s =~ /3/) ? "aho" : ""
  puts ((n % 5 == 0) ? str + "bow" : ((str == "") ? n.to_s : str))
}||<
<<

2.ビール瓶が99本

こんな感じ。微妙にゴルフしてます。

>>
>|ruby|
def to_str(n); n > 0 ? n :"No"; end
def bottles(n)
  "#{to_str(n)} bottles of beer on the wall\n"+
  "#{to_str(n)} bottles of beer\n"+
  "Take one down and pass it around\n"+
  "#{to_str(n-1)} bottles of beer on the wall"
end
99.downto(0){|n| puts bottles(n); puts }}

3.石取り

うーん・・・時を見て書こう。