Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

README to Markdown and credit to Alex D

  • Loading branch information...
commit 7d4f22f94d98412a1cb603724291049533ece1f0 1 parent 796316f
Dan Buettner authored
Showing with 12 additions and 7 deletions.
  1. +6 −2 README → README.markdown
  2. +6 −5 powerball.rb
View
8 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
- ➤
+ ➤
+ ```
View
11 powerball.rb
@@ -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
@@ -24,6 +21,10 @@ def most_popular_n(n)
end
ret
end
+
+ def most_popular
+ most_popular_n(1).first
+ end
end
white_balls = []
Please sign in to comment.
Something went wrong with that request. Please try again.