Search found 3 matches

by facetoe
Wed Jun 13, 2012 2:48 pm
Forum: Challenges Solved
Topic: Lorem Ipsum
Replies: 34
Views: 8428

Easy as pie:

Code: Select all

words = {}

File.open('file', 'r').readlines.each do |line|
  line.split.each do |word|
      word.gsub!(/[[:punct:]]/, '')
      if words[word]==nil
        words.merge!(Hash[word=>0])
      else
        words[word]+=1
      end
    end
  
end

puts words.sort_by {|k,v|v}.first
by facetoe
Wed Jun 13, 2012 2:30 pm
Forum: Challenges Solved
Topic: UpCount
Replies: 28
Views: 6527

I also just ported it to C.
by facetoe
Wed Jun 13, 2012 1:51 pm
Forum: Challenges Solved
Topic: 3280
Replies: 20
Views: 2509

Another Ruby solution:

Code: Select all

words = {}

File.open('file', 'r').readlines.each do |line|
  line.split.each do |word|
    if word.size == 9
      if words[word]==nil
        words.merge!(Hash[word=>0])
      else
        words[word]+=1
      end
    end
  end
end

puts words.max_by{|k,v|v}