SlideShare a Scribd company logo
Rubyコードの最適化
Rubyコードの最適化
Rubyコードの最適化
Rubyコードの最適化
Rubyコードの最適化
Rubyコードの最適化
Rubyコードの最適化
Rubyコードの最適化
Rubyコードの最適化
Rubyコードの最適化
Rubyコードの最適化
Rubyコードの最適化
Rubyコードの最適化
Rubyコードの最適化
FNAME = "KEN_ALL.CSV"
count = []
File.open(FNAME, "r:SJIS:UTF-8") do |f|
while line = f.gets
next unless line =~ /[ ]/
c = count.find{|a| a.first == Regexp.last_match[0] }
unless c
c = [Regexp.last_match[0], []]
count.push c
end
c[1] << line
end
end
p count
.sort{|a, b| a.last.length <=> b.last.length }
.map{|k, v| [k, v.length] }
#=> [[" ", 8079], [" ", 8392], [" ", 11271], [" ",
15017]]
Rubyコードの最適化
FNAME = "KEN_ALL.CSV"
count = []
File.open(FNAME, "r:SJIS:UTF-8") do |f|
while line = f.gets
next unless line =~ /[ ]/
c = count.find{|a| a.first == Regexp.last_match[0] }
unless c
c = [Regexp.last_match[0], []]
count.push c
end
c[1] << line
end
end
p count
.sort{|a, b| a.last.length <=> b.last.length }
.map{|k, v| [k, v.length] }
#=>[[" ", 8079], [" ", 8392], [" ", 11271], [" ",
15017]]
FNAME = "KEN_ALL.CSV"
count = []
body = nil
File.read(FNAME, “r:SJIS:UTF-8"){|f|
body = f.read
end
body.each_line do |line|
next unless line =~ /[ ]/
c = count.find{|a| a.first == Regexp.last_match[0] }
unless c
c = [Regexp.last_match[0], []]
count.push c
end
c[1] << line
end
p count
.sort{|a, b| a.last.length <=> b.last.length }
.map{|k, v| [k, v.length] }
#=>[[" ", 8079], [" ", 8392], [" ", 11271], [" ",
FNAME = "KEN_ALL.CSV"
count = []
body = nil
File.read(FNAME, “r:SJIS:UTF-8"){|f|
body = f.read
end
body.each_line do |line|
next unless line =~ /[ ]/
c = count.find{|a| a.first == Regexp.last_match[0] }
unless c
c = [Regexp.last_match[0], []]
count.push c
end
c[1] << line
end
p count
.sort{|a, b| a.last.length <=> b.last.length }
.map{|k, v| [k, v.length] }
#=>[[" ", 8079], [" ", 8392], [" ", 11271], [" ",
15017]]
FNAME = "KEN_ALL.CSV"
count = {}
body = nil
File.open(FNAME, "r:SJIS:UTF-8") do
|f| body = f.read
end
body.each_line do |line|
next unless line =~ /[ ]/
count[Regexp.last_match[0]] ||= []
count[Regexp.last_match[0]] << line
end
p count
.sort{|a, b| a.last.length <=> b.last.length }
.map{|k, v| [k, v.length] }
#=>[[" ", 8079], [" ", 8392], [" ", 11271], [" ",
15017]]
FNAME = "KEN_ALL.CSV"
count = {}
body = nil
File.open(FNAME, "r:SJIS:UTF-8") do
|f| body = f.read
end
body.each_line do |line|
next unless line =~ /[ ]/
count[Regexp.last_match[0]] ||= []
count[Regexp.last_match[0]] << line
end
p count
.sort{|a, b| a.last.length <=> b.last.length }
.map{|k, v| [k, v.length] }
#=>[[" ", 8079], [" ", 8392], [" ", 11271], [" ",
15017]]
FNAME = "KEN_ALL.CSV"
count = {}
body = nil
File.open(FNAME, "r:SJIS:UTF-8") do
|f| body = f.read
end
body.each_line do |line|
next unless line =~ /[ ]/
count[Regexp.last_match[0]] ||= 0
count[Regexp.last_match[0]] += 1
end
p count
.sort{|a, b| a.last <=> b.last }
FNAME = "KEN_ALL.CSV"
count = {}
body = nil
File.open(FNAME, "r:SJIS:UTF-8") do
|f| body = f.read
end
body.each_line do |line|
next unless line =~ /[ ]/
count[Regexp.last_match[0]] ||= 0
count[Regexp.last_match[0]] += 1
end
p count
.sort{|a, b| a.last <=> b.last }
FNAME = "KEN_ALL.CSV"
count = {}
body = nil
File.open(FNAME, "r:SJIS:UTF-8") do
|f| body = f.read
end
reg = /[ ]/
body.each_line do |line|
next unless line =~ reg
count[Regexp.last_match[0]] ||= 0
count[Regexp.last_match[0]] += 1
end
p count
.sort{|a, b| a.last <=> b.last }
FNAME = "KEN_ALL.CSV"
count = {}
body = nil
File.open(FNAME, "r:SJIS:UTF-8") do
|f| body = f.read
end
reg = /[ ]/
body.each_line do |line|
next unless line =~ reg
count[Regexp.last_match[0]] ||= 0
count[Regexp.last_match[0]] += 1
end
p count
.sort{|a, b| a.last <=> b.last }
FNAME = "KEN_ALL.CSV"
count = {}
body = nil
File.open(FNAME, "r:SJIS:UTF-8") do
|f| body = f.read
end
reg = /[ ]/
body.each_line do |line|
next unless line =~ reg
k = Regexp.last_match[0]
count[k] ||= 0
count[k] += 1
end
p count
.sort{|a, b| a.last <=> b.last }
FNAME = "KEN_ALL.CSV"
count = {}
body = nil
File.open(FNAME, "r:SJIS:UTF-8") do
|f| body = f.read
end
reg = /[ ]/
body.each_line do |line|
next unless line =~ reg
k = Regexp.last_match[0]
count[k] ||= 0
count[k] += 1
end
p count
.sort{|a, b| a.last <=> b.last }
FNAME = "KEN_ALL.CSV"
count = {” ” => 0}
count = Hash.new { 0 }
body = nil
File.open(FNAME, "r:SJIS:UTF-8") do
|f| body = f.read
end
reg = /[ ]/
body.each_line do |line|
next unless line =~ reg
k = Regexp.last_match[0]
count[k] ||= 0
count[k] += 1
end
p count.sort_by{|k, v| v }
Rubyコードの最適化
Rubyコードの最適化
Rubyコードの最適化
Rubyコードの最適化
Rubyコードの最適化
Rubyコードの最適化
Rubyコードの最適化
Rubyコードの最適化

More Related Content

PDF
Practical Data Science : Data Cleaning and Summarising
DOC
Junos commands
PPTX
2 19-2018-mean of all runs
PDF
Feedback
PDF
Vue.js ハンズオン資料
PPTX
低レイヤから見たrubyプログラミング
PPTX
Cocos2d-xハンズオン#1 in 大阪
PDF
まじょのおしごとの裏側
Practical Data Science : Data Cleaning and Summarising
Junos commands
2 19-2018-mean of all runs
Feedback
Vue.js ハンズオン資料
低レイヤから見たrubyプログラミング
Cocos2d-xハンズオン#1 in 大阪
まじょのおしごとの裏側

Viewers also liked (15)

PDF
TOEICテスト学習コース~ETS公式問題集収録~
PDF
デバッガでデバッグしない
PDF
Next GAE Heroku を使って 3分でRailsアプリをリリース
PDF
テスト駆動開発入門
ODP
Twitterでネットストーカーをしよう
PDF
僕が勉強をする モチベーションと勉強法
PDF
私はいかにしてpull request を行ったか - あるいは social development について
PDF
よい名前を付けましょう リーダブルなんたらとか
PDF
Railsの今昔
ODP
Rails3使用雑感
PDF
15分でできるSQLインジェクション
PDF
Dockerプレゼン
PDF
Gitの使い方あれこれ
PDF
Vue.js入門
PDF
GCS2013 リーンソフトウェア開発から見るゲーム開発7つのムダ
TOEICテスト学習コース~ETS公式問題集収録~
デバッガでデバッグしない
Next GAE Heroku を使って 3分でRailsアプリをリリース
テスト駆動開発入門
Twitterでネットストーカーをしよう
僕が勉強をする モチベーションと勉強法
私はいかにしてpull request を行ったか - あるいは social development について
よい名前を付けましょう リーダブルなんたらとか
Railsの今昔
Rails3使用雑感
15分でできるSQLインジェクション
Dockerプレゼン
Gitの使い方あれこれ
Vue.js入門
GCS2013 リーンソフトウェア開発から見るゲーム開発7つのムダ
Ad

Recently uploaded (20)

PDF
composite construction of structures.pdf
PPTX
UNIT 4 Total Quality Management .pptx
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
Well-logging-methods_new................
PPTX
Sustainable Sites - Green Building Construction
PPT
Mechanical Engineering MATERIALS Selection
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
Welding lecture in detail for understanding
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
additive manufacturing of ss316l using mig welding
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
Digital Logic Computer Design lecture notes
PPTX
web development for engineering and engineering
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
composite construction of structures.pdf
UNIT 4 Total Quality Management .pptx
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Well-logging-methods_new................
Sustainable Sites - Green Building Construction
Mechanical Engineering MATERIALS Selection
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Welding lecture in detail for understanding
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Foundation to blockchain - A guide to Blockchain Tech
additive manufacturing of ss316l using mig welding
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Digital Logic Computer Design lecture notes
web development for engineering and engineering
Embodied AI: Ushering in the Next Era of Intelligent Systems
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
Ad

Rubyコードの最適化

  • 15. FNAME = "KEN_ALL.CSV" count = [] File.open(FNAME, "r:SJIS:UTF-8") do |f| while line = f.gets next unless line =~ /[ ]/ c = count.find{|a| a.first == Regexp.last_match[0] } unless c c = [Regexp.last_match[0], []] count.push c end c[1] << line end end p count .sort{|a, b| a.last.length <=> b.last.length } .map{|k, v| [k, v.length] } #=> [[" ", 8079], [" ", 8392], [" ", 11271], [" ", 15017]]
  • 17. FNAME = "KEN_ALL.CSV" count = [] File.open(FNAME, "r:SJIS:UTF-8") do |f| while line = f.gets next unless line =~ /[ ]/ c = count.find{|a| a.first == Regexp.last_match[0] } unless c c = [Regexp.last_match[0], []] count.push c end c[1] << line end end p count .sort{|a, b| a.last.length <=> b.last.length } .map{|k, v| [k, v.length] } #=>[[" ", 8079], [" ", 8392], [" ", 11271], [" ", 15017]]
  • 18. FNAME = "KEN_ALL.CSV" count = [] body = nil File.read(FNAME, “r:SJIS:UTF-8"){|f| body = f.read end body.each_line do |line| next unless line =~ /[ ]/ c = count.find{|a| a.first == Regexp.last_match[0] } unless c c = [Regexp.last_match[0], []] count.push c end c[1] << line end p count .sort{|a, b| a.last.length <=> b.last.length } .map{|k, v| [k, v.length] } #=>[[" ", 8079], [" ", 8392], [" ", 11271], [" ",
  • 19. FNAME = "KEN_ALL.CSV" count = [] body = nil File.read(FNAME, “r:SJIS:UTF-8"){|f| body = f.read end body.each_line do |line| next unless line =~ /[ ]/ c = count.find{|a| a.first == Regexp.last_match[0] } unless c c = [Regexp.last_match[0], []] count.push c end c[1] << line end p count .sort{|a, b| a.last.length <=> b.last.length } .map{|k, v| [k, v.length] } #=>[[" ", 8079], [" ", 8392], [" ", 11271], [" ", 15017]]
  • 20. FNAME = "KEN_ALL.CSV" count = {} body = nil File.open(FNAME, "r:SJIS:UTF-8") do |f| body = f.read end body.each_line do |line| next unless line =~ /[ ]/ count[Regexp.last_match[0]] ||= [] count[Regexp.last_match[0]] << line end p count .sort{|a, b| a.last.length <=> b.last.length } .map{|k, v| [k, v.length] } #=>[[" ", 8079], [" ", 8392], [" ", 11271], [" ", 15017]]
  • 21. FNAME = "KEN_ALL.CSV" count = {} body = nil File.open(FNAME, "r:SJIS:UTF-8") do |f| body = f.read end body.each_line do |line| next unless line =~ /[ ]/ count[Regexp.last_match[0]] ||= [] count[Regexp.last_match[0]] << line end p count .sort{|a, b| a.last.length <=> b.last.length } .map{|k, v| [k, v.length] } #=>[[" ", 8079], [" ", 8392], [" ", 11271], [" ", 15017]]
  • 22. FNAME = "KEN_ALL.CSV" count = {} body = nil File.open(FNAME, "r:SJIS:UTF-8") do |f| body = f.read end body.each_line do |line| next unless line =~ /[ ]/ count[Regexp.last_match[0]] ||= 0 count[Regexp.last_match[0]] += 1 end p count .sort{|a, b| a.last <=> b.last }
  • 23. FNAME = "KEN_ALL.CSV" count = {} body = nil File.open(FNAME, "r:SJIS:UTF-8") do |f| body = f.read end body.each_line do |line| next unless line =~ /[ ]/ count[Regexp.last_match[0]] ||= 0 count[Regexp.last_match[0]] += 1 end p count .sort{|a, b| a.last <=> b.last }
  • 24. FNAME = "KEN_ALL.CSV" count = {} body = nil File.open(FNAME, "r:SJIS:UTF-8") do |f| body = f.read end reg = /[ ]/ body.each_line do |line| next unless line =~ reg count[Regexp.last_match[0]] ||= 0 count[Regexp.last_match[0]] += 1 end p count .sort{|a, b| a.last <=> b.last }
  • 25. FNAME = "KEN_ALL.CSV" count = {} body = nil File.open(FNAME, "r:SJIS:UTF-8") do |f| body = f.read end reg = /[ ]/ body.each_line do |line| next unless line =~ reg count[Regexp.last_match[0]] ||= 0 count[Regexp.last_match[0]] += 1 end p count .sort{|a, b| a.last <=> b.last }
  • 26. FNAME = "KEN_ALL.CSV" count = {} body = nil File.open(FNAME, "r:SJIS:UTF-8") do |f| body = f.read end reg = /[ ]/ body.each_line do |line| next unless line =~ reg k = Regexp.last_match[0] count[k] ||= 0 count[k] += 1 end p count .sort{|a, b| a.last <=> b.last }
  • 27. FNAME = "KEN_ALL.CSV" count = {} body = nil File.open(FNAME, "r:SJIS:UTF-8") do |f| body = f.read end reg = /[ ]/ body.each_line do |line| next unless line =~ reg k = Regexp.last_match[0] count[k] ||= 0 count[k] += 1 end p count .sort{|a, b| a.last <=> b.last }
  • 28. FNAME = "KEN_ALL.CSV" count = {” ” => 0} count = Hash.new { 0 } body = nil File.open(FNAME, "r:SJIS:UTF-8") do |f| body = f.read end reg = /[ ]/ body.each_line do |line| next unless line =~ reg k = Regexp.last_match[0] count[k] ||= 0 count[k] += 1 end p count.sort_by{|k, v| v }