Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Rubyコードの最適化
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
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]]
16.
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 }