Skip to content

Commit

Permalink
README to Markdown and credit to Alex D
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Buettner committed Feb 21, 2012
1 parent 796316f commit 7d4f22f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
8 changes: 6 additions & 2 deletions README → README.markdown
@@ -1,9 +1,13 @@
Simple analysis of Powerball lottery number stats, using Ruby's Enumerable.
# Powerball Numbers

### Simple analysis of Powerball lottery number stats, using Ruby's Enumerable.

```bash
➤ ruby ./powerball.rb
Getting Powerball drawing data from 02/20/2012 back to 11/01/1997 ...
Got 1738801 bytes of Powerball data. Stand by for parsing.
Examining results of 1493 drawings...
Top 5 numbers: 41, 20, 32, 16, 26
Top Powerball: 37
```
11 changes: 6 additions & 5 deletions powerball.rb
Expand Up @@ -4,17 +4,14 @@
require 'date'

module Enumerable
# with a big nod to Alex D who posted at StackOverflow
# http://stackoverflow.com/questions/9127971/sort-array-by-popularity-and-time-in-ruby
def to_histogram
result = Hash.new(0)
each { |x| result[x] += 1 }
result
end

def most_popular
h = self.to_histogram
max_by { |x| h[x] }
end

def most_popular_n(n)
ret = []
h = self.to_histogram
Expand All @@ -24,6 +21,10 @@ def most_popular_n(n)
end
ret
end

def most_popular
most_popular_n(1).first
end
end

white_balls = []
Expand Down

0 comments on commit 7d4f22f

Please sign in to comment.