開発環境
- OS X Lion - Apple(OS)
- TextWrangler(Text Editor) (BBEditの機能制限無料版、light版)
- Script言語:Ruby
『初めてのプログラミング 第2版』(Chris Pine 著、長尾 高弘 訳、オライリー・ジャパン、2010年、ISBN978-4-87311-469-9)の 8章(配列とイテレータ), 8.3(練習問題)、配列の構築とソート を解いてみる。
その他参考書籍
- 『プログラミング言語 Ruby』David Flanagan, まつもと ゆきひろ 著 、卜部 昌平 監訳、長尾 高弘 訳、オライリー・ジャパン、2009年、ISBN978-4-87311-394-4)
- Rubyクックブック ―エキスパートのための応用レシピ集
配列の構築とソート
コード(TextWrangler)
sample.rb
#!/usr/bin/env ruby # -*- coding: utf-8 -*- puts "配列に書くのする単語を入力(空白で終了)" words = [] while true word = gets.chomp break if word =~ /^\s*$/ words.push word end sorted_words = words.sort puts "ソート前", words puts "ソート後", sorted_words
入出力結果(Terminal)
$ ./sample.rb 配列に書くのする単語を入力(空白で終了) c# python perl c ruby php ソート前 c# python perl c ruby php ソート後 c c# perl php python ruby $
0 コメント:
コメントを投稿