Skip to content

Instantly share code, notes, and snippets.

@rgreenjr
Created January 18, 2010 15:30
Show Gist options
  • Select an option

  • Save rgreenjr/280096 to your computer and use it in GitHub Desktop.

Select an option

Save rgreenjr/280096 to your computer and use it in GitHub Desktop.

Revisions

  1. rgreenjr revised this gist Jan 18, 2010. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions word_freq.rb
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    #!/usr/bin/env ruby -w
    text = IO.read(ARGV.first)
    words = text.split(/[^a-zA-Z]/)
    freqs = Hash.new(0)
  2. rgreenjr created this gist Jan 18, 2010.
    7 changes: 7 additions & 0 deletions word_freq.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    text = IO.read(ARGV.first)
    words = text.split(/[^a-zA-Z]/)
    freqs = Hash.new(0)
    words.each { |word| freqs[word] += 1 }
    freqs = freqs.sort_by { |x, y| y }
    freqs.reverse!
    freqs.each { |word, freq| puts sprintf("%20s %s", word, freq.to_s) }