2012年4月2日月曜日

開発環境

『初めてのプログラミング 第2版』(Chris Pine 著、長尾 高弘 訳、オライリー・ジャパン、2010年、ISBN978-4-87311-469-9)の 7章(フロー制御), 7.5(練習問題)「壁井にビールが99本」を解いてみる。

その他参考書籍

「壁井にビールが99本」

コード(TextWrangler)

#!/usr/bin/env ruby
#encoding: utf-8

n = 5
while true
  puts "#{n} bottles of beer on the wall, #{n} bottles of beer!"
  n -= 1
  break if n == 1
  puts "Take one down, pass it around, #{n} bottles of beer on the wall!"
end
puts "Take one down, pass it around, #{n} bottle of beer on the wall!"
puts "#{n} bottle of beer on the wall, #{n} bottle of beer!"
puts "Take one down, pass it around, no more bottles of beer on the wall!"

入出力結果(Terminal)

$ ruby ruby_program.rb
5 bottles of beer on the wall, 5 bottles of beer!
Take one down, pass it around, 4 bottles of beer on the wall!
4 bottles of beer on the wall, 4 bottles of beer!
Take one down, pass it around, 3 bottles of beer on the wall!
3 bottles of beer on the wall, 3 bottles of beer!
Take one down, pass it around, 2 bottles of beer on the wall!
2 bottles of beer on the wall, 2 bottles of beer!
Take one down, pass it around, 1 bottle of beer on the wall!
1 bottle of beer on the wall, 1 bottle of beer!
Take one down, pass it around, no more bottles of beer on the wall!
$

今回の周ではirb(インタラクティブRuby)も少しずつ活用してみることに。

まだ上記の本を入手してないのでまた最初から。

本書を続けつつ、上記の本を早く入手してそっちに切り替え。

0 コメント:

コメントを投稿