rubylabs 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/demos.rb CHANGED
@@ -1,15 +1,12 @@
1
- =begin rdoc
2
-
3
- Methods in this module are not intended to be used by students. They are
4
- implemented here so they can be tested before being included in the book
5
- or lecture slides. Instructors can also load this module to use the methods
6
- in lectures.
7
-
8
- =end
1
+ # Methods in this module are not intended to be used by students. They are
2
+ # included as part of the RubyLabs gem so they can be tested before being included in the book
3
+ # or lecture slides. Instructors can also load this module to use the methods
4
+ # in lectures.
5
+ #
9
6
 
10
7
  module RubyLabs
11
8
 
12
- module Demos
9
+ module Demos # :nodoc: all
13
10
 
14
11
  =begin rdoc
15
12
  Convert the temperature +f+ (in degrees Fahrenheit) into the equivalent
@@ -165,6 +162,20 @@ module Demos
165
162
  def make_order(size, kind)
166
163
  puts "I'll have a " + drink_cup(size) + " " + kind + ", please."
167
164
  end
165
+
166
+ =begin rdoc
167
+ Verification of numbers shown in the table for the birthday paradox. Call
168
+ birthday(n,m) to make a table with n rows and fill it with m random words.
169
+ Return true if any row has more than one item.
170
+ =end
171
+
172
+ def birthday(n, m)
173
+ t = HashTable.new(n)
174
+ TestArray.new(m, :words).each { |s| t.insert(s) }
175
+ # puts t
176
+ t.table.each { |row| return true if row && row.length > 1 }
177
+ return false
178
+ end
168
179
 
169
180
  end # Demos
170
181