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/README.rdoc +15 -6
- data/Rakefile +3 -0
- data/VERSION +1 -1
- data/lib/bitlab.rb +593 -328
- data/lib/demos.rb +20 -9
- data/lib/elizalab.rb +660 -507
- data/lib/hashlab.rb +289 -192
- data/lib/introlab.rb +33 -38
- data/lib/iterationlab.rb +117 -61
- data/lib/marslab.rb +608 -475
- data/lib/randomlab.rb +227 -121
- data/lib/recursionlab.rb +197 -140
- data/lib/rubylabs.rb +936 -390
- data/lib/sievelab.rb +32 -24
- data/lib/spherelab.rb +308 -220
- data/lib/tsplab.rb +634 -312
- data/test/bit_test.rb +4 -4
- data/test/tsp_test.rb +18 -0
- metadata +2 -2
data/lib/demos.rb
CHANGED
@@ -1,15 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|
|