rubylabs 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +9 -0
- data/Rakefile +63 -0
- data/VERSION +1 -0
- data/bin/bb.rb +12 -0
- data/bin/statistics2-0.53/ext/extconf.rb +11 -0
- data/bin/statistics2-0.53/ext/show.rb +11 -0
- data/bin/statistics2-0.53/ext/t.rb +46 -0
- data/bin/statistics2-0.53/mklist.rb +26 -0
- data/bin/statistics2-0.53/sample-tbl.rb +129 -0
- data/bin/statistics2-0.53/statistics2.rb +532 -0
- data/bin/statistics2-0.53/t-inv.rb +54 -0
- data/bin/statistics2.rb +532 -0
- data/data/aafreq.txt +20 -0
- data/data/cars.txt +50 -0
- data/data/century.txt +1 -0
- data/data/colors.txt +64 -0
- data/data/earth.yaml +15 -0
- data/data/fruit.txt +45 -0
- data/data/hacodes.txt +35 -0
- data/data/hafreq.txt +16 -0
- data/data/hvfreq.txt +5 -0
- data/data/nbody.R +23 -0
- data/data/nbody.out +731 -0
- data/data/nbody.pdf +3111 -0
- data/data/nbody.png +0 -0
- data/data/nbody3d.pdf +3201 -0
- data/data/outer.pdf +182785 -0
- data/data/solar.dat +36501 -0
- data/data/solarsystem.txt +17 -0
- data/data/suits.txt +1 -0
- data/data/wordlist.txt +210653 -0
- data/lib/bitlab.rb +624 -0
- data/lib/elizalab.rb +523 -0
- data/lib/encryptionlab.rb +42 -0
- data/lib/hashlab.rb +224 -0
- data/lib/introlab.rb +14 -0
- data/lib/iterationlab.rb +130 -0
- data/lib/randomlab.rb +294 -0
- data/lib/recursionlab.rb +228 -0
- data/lib/rubylabs.rb +507 -0
- data/lib/sievelab.rb +58 -0
- data/lib/sortlab.rb +213 -0
- data/lib/spherelab.rb +352 -0
- data/lib/temps.rb +41 -0
- data/lib/tsplab.rb +416 -0
- data/lib/viewer.rb +65 -0
- data/test/bit_test.rb +175 -0
- data/test/encryption_test.rb +20 -0
- data/test/iteration_test.rb +40 -0
- data/test/random_test.rb +64 -0
- data/test/recursion_test.rb +47 -0
- data/test/rubylabs_test.rb +18 -0
- data/test/sieve_test.rb +28 -0
- data/test/sphere_test.rb +130 -0
- data/test/temps_test.rb +24 -0
- data/test/test_helper.rb +18 -0
- metadata +112 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 John S. Conery
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
= rubylabs
|
2
|
+
|
3
|
+
The modules in this Gem have methods and data for lab projects in the textbook
|
4
|
+
<em>The Science of Computing: A Problem Solving Approach</em>. There is one module
|
5
|
+
for each chapter, plus a set of common methods shared by more than one module.
|
6
|
+
|
7
|
+
== Copyright
|
8
|
+
|
9
|
+
Copyright (c) 2009 John S. Conery. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
8
|
+
gem.name = "rubylabs"
|
9
|
+
gem.summary = %Q{Software and data for lab projects in the Science of Computing text.}
|
10
|
+
gem.description = %Q{A set of modules for interactive experiments in an introductory computer science class.}
|
11
|
+
gem.email = "conery@cs.uoregon.edu"
|
12
|
+
gem.homepage = "http://github.com/conery/rubylabs"
|
13
|
+
gem.authors = ["conery"]
|
14
|
+
gem.files = FileList['[A-Z]*', 'lib/**/*.rb', 'data/*', 'bin/**/*.rb']
|
15
|
+
gem.test_files = FileList['test/**/*.rb']
|
16
|
+
gem.rubyforge_project = "rubylabs"
|
17
|
+
end
|
18
|
+
|
19
|
+
Jeweler::RubyforgeTasks.new
|
20
|
+
Jeweler::GemcutterTasks.new
|
21
|
+
|
22
|
+
rescue LoadError
|
23
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
24
|
+
end
|
25
|
+
|
26
|
+
require 'rake/testtask'
|
27
|
+
Rake::TestTask.new(:test) do |test|
|
28
|
+
test.libs << 'lib' << 'test'
|
29
|
+
test.pattern = 'test/**/*_test.rb'
|
30
|
+
test.verbose = true
|
31
|
+
end
|
32
|
+
|
33
|
+
begin
|
34
|
+
require 'rcov/rcovtask'
|
35
|
+
Rcov::RcovTask.new do |test|
|
36
|
+
test.libs << 'test'
|
37
|
+
test.pattern = 'test/**/*_test.rb'
|
38
|
+
# test.verbose = true
|
39
|
+
end
|
40
|
+
rescue LoadError
|
41
|
+
task :rcov do
|
42
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
task :default => :test
|
48
|
+
|
49
|
+
require 'rake/rdoctask'
|
50
|
+
Rake::RDocTask.new do |rdoc|
|
51
|
+
if File.exist?('VERSION.yml')
|
52
|
+
config = YAML.load(File.read('VERSION.yml'))
|
53
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
54
|
+
else
|
55
|
+
version = ""
|
56
|
+
end
|
57
|
+
|
58
|
+
rdoc.rdoc_dir = 'rdoc'
|
59
|
+
rdoc.title = "rubylabs #{version}"
|
60
|
+
rdoc.rdoc_files.include('README*')
|
61
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
62
|
+
end
|
63
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.5.4
|
data/bin/bb.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#! /usr/bin/ruby -rubygems
|
2
|
+
|
3
|
+
# From: http://www.rubyagent.com/2007/03/starting-multi-agent-system-environment
|
4
|
+
|
5
|
+
require 'drb/drb'
|
6
|
+
require 'rinda/tuplespace'
|
7
|
+
|
8
|
+
DRb.start_service("druby://localhost:53783", Rinda::TupleSpace.new)
|
9
|
+
|
10
|
+
puts 'The blackboard is running...'
|
11
|
+
|
12
|
+
DRb.thread.join
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "mkmf"
|
2
|
+
create_makefile("statistics2")
|
3
|
+
open("Makefile", "a") do |f|
|
4
|
+
f << "test:\n\truby -I./lib:. t.rb\n"
|
5
|
+
f << "\n"
|
6
|
+
f << "uninstall:\n"
|
7
|
+
f << "\t@echo rm $(RUBYLIBDIR)/statistics2.rb\n"
|
8
|
+
f << "\t@$(RM) $(RUBYLIBDIR)/statistics2.rb\n"
|
9
|
+
f << "\t@echo rm $(RUBYARCHDIR)/statistics2.{o,so}\n"
|
10
|
+
f << "\t@$(RM) $(RUBYARCHDIR)/statistics2.{o,so}\n"
|
11
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
$test = true
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift ".."
|
5
|
+
require 'sample-tbl'
|
6
|
+
|
7
|
+
eval(File.read('../statistics2.rb').sub(/\bStatistics2\b/, 'Statistics20'))
|
8
|
+
$mod0 = Statistics20
|
9
|
+
|
10
|
+
require 'statistics2.so'
|
11
|
+
$mod = Statistics2
|
12
|
+
|
13
|
+
class T_Statistics2 < Test::Unit::TestCase
|
14
|
+
|
15
|
+
def test_normal
|
16
|
+
norm_tbl(0.0, 3.1) do |x|
|
17
|
+
a, b = $mod.normal___x(x), $mod0.normal___x(x)
|
18
|
+
assert_in_delta a, b, 0.000001
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_chi
|
23
|
+
chi2_tbl() do |n, x|
|
24
|
+
a, b = $mod.pchi2_x(n, x), $mod0.pchi2_x(n, x)
|
25
|
+
assert_in_delta a/b, 1.0, 0.01
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_t
|
30
|
+
t_tbl() do |n, x|
|
31
|
+
a, b = $mod.ptx__x(n, x), $mod.ptx__x(n, x)
|
32
|
+
assert_in_delta a, b, 0.001
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_f
|
37
|
+
[0.01, 0.025, 0.05].each do |opt|
|
38
|
+
f_tbl(opt) do |n1, n2, y|
|
39
|
+
a, b = $mod.pf_x(n1, n2, y), $mod0.pf_x(n1, n2, y)
|
40
|
+
assert_in_delta a/b, 1.0, 0.01
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
require "t-inv.rb"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
cmd = "ruby sample-tbl.rb"
|
3
|
+
param_tbl = [["norm", "tbl-nomral.tbl"],
|
4
|
+
["chi2", "tbl-chi2.tbl"],
|
5
|
+
["t", "tbl-t.tbl"],
|
6
|
+
["f 0.05", "tbl-F50.tbl"],
|
7
|
+
["f 0.025", "tbl-F25.tbl"],
|
8
|
+
["f 0.01", "tbl-F10.tbl"]]
|
9
|
+
|
10
|
+
unless dir = ARGV.shift
|
11
|
+
puts "Usage: $0 DIR"
|
12
|
+
puts "-- This script creates some tables of distributions:"
|
13
|
+
param_tbl.each do |mod, tbl|
|
14
|
+
puts " " + mod + " => " + tbl
|
15
|
+
end
|
16
|
+
exit
|
17
|
+
end
|
18
|
+
|
19
|
+
unless File.directory? dir
|
20
|
+
system("mkdir #{dir}")
|
21
|
+
end
|
22
|
+
|
23
|
+
param_tbl.each do |pa, tbl|
|
24
|
+
file = File.join(dir, tbl)
|
25
|
+
system("#{cmd} #{pa} > #{file}")
|
26
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
if $test
|
4
|
+
def nop(*a); ""; end
|
5
|
+
alias _sprintf nop
|
6
|
+
alias _printf nop
|
7
|
+
alias _puts nop
|
8
|
+
else
|
9
|
+
alias _sprintf sprintf
|
10
|
+
alias _printf printf
|
11
|
+
alias _puts puts
|
12
|
+
end
|
13
|
+
|
14
|
+
def norm_line(x, n)
|
15
|
+
s = sprintf("%1.1f|", x)
|
16
|
+
(0.00).step(0.09, 0.01) do |y|
|
17
|
+
s << _sprintf(" %1.#{n}f", yield(x + y))
|
18
|
+
end
|
19
|
+
s
|
20
|
+
end
|
21
|
+
|
22
|
+
def norm_tbl(s, e, ln = nil, tn = nil, &b)
|
23
|
+
n = 4
|
24
|
+
unless ln
|
25
|
+
_printf(" " + (" "*(n-1) + "%1.2f")*10 + "\n", * (0..9).map {|x| x*0.01})
|
26
|
+
end
|
27
|
+
i = 0
|
28
|
+
(s.to_f).step(e.to_f, 0.1) do |x|
|
29
|
+
next if ln && ln.to_i != i+1
|
30
|
+
_puts norm_line(x, n, &b)
|
31
|
+
i += 1
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def chi2_tbl(ln = nil, tn = nil)
|
36
|
+
pers = [0.995, 0.99, 0.975, 0.95, 0.05, 0.025, 0.01, 0.005]
|
37
|
+
arbi = (1..30).to_a + [40, 60, 80, 100]
|
38
|
+
form = " %7.5f"
|
39
|
+
unless ln
|
40
|
+
_printf(" "); pers.each do |a|; _printf(form, a); end; _puts
|
41
|
+
end
|
42
|
+
arbi.each_with_index do |n, i|
|
43
|
+
next if ln && ln.to_i != i+1
|
44
|
+
_printf("%4d|", n) unless tn
|
45
|
+
pers.each_with_index do |a, j|
|
46
|
+
next if tn && tn.to_i != j+1
|
47
|
+
form = case n
|
48
|
+
when 1; a >= 0.95 ? " %.4e" : " %6.3f"
|
49
|
+
when 2..5; a >= 0.95 ? " %7.5f" : " %7.3f"
|
50
|
+
when 6..24; " %7.3f"
|
51
|
+
else 26..100; " %7.2f"
|
52
|
+
end
|
53
|
+
_printf(form, yield(n, a))
|
54
|
+
end
|
55
|
+
_puts
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def t_tbl(ln = nil, tn = nil)
|
60
|
+
pers = [0.5, 0.4, 0.3, 0.2, 0.1, 0.05, 0.02, 0.01, 0.001]
|
61
|
+
arbi = (1..30).to_a + [40, 60, 120]#, 9999]
|
62
|
+
form = " %7.3f"
|
63
|
+
unless ln
|
64
|
+
_printf(" "); pers.each do |a|; _printf(form, a); end; _puts
|
65
|
+
end
|
66
|
+
arbi.each_with_index do |n, i|
|
67
|
+
next if ln && ln.to_i != i+1
|
68
|
+
_printf("%4d|", n) unless tn
|
69
|
+
pers.each_with_index do |a, j|
|
70
|
+
next if tn && tn.to_i != j+1
|
71
|
+
_printf(form, yield(n, a))
|
72
|
+
end
|
73
|
+
_puts
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def f_tbl(a, k1 = nil, k2 = nil)
|
78
|
+
arbi1 = (1..10).to_a + [12, 15, 20, 24, 30, 40, 60, 120]#, 9999]
|
79
|
+
arbi2 = (1..30).to_a + [40, 60, 120]#, 9999]
|
80
|
+
unless k1
|
81
|
+
_printf(" "); arbi1.each do |n1|; _printf(" %4d", n1); end; _puts
|
82
|
+
end
|
83
|
+
arbi2.each do |n2|
|
84
|
+
form = n2 == 1 ? " %4d" : n2 == 2 ? " %4.1f" : " %4.2f"
|
85
|
+
next if k2 && k2.to_i != n2
|
86
|
+
_printf("%4d|", n2) unless k2
|
87
|
+
arbi1.each do |n1|
|
88
|
+
next if k1 && k1.to_i != n1
|
89
|
+
_printf(form, yield(n1, n2, a.to_f))
|
90
|
+
end
|
91
|
+
_puts
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def show_tbl(mod, dist, *opts)
|
96
|
+
case dist
|
97
|
+
when nil, "norm"
|
98
|
+
norm_tbl(0.0, 3.1, *opts) do |x|
|
99
|
+
mod.normal___x(x)
|
100
|
+
end
|
101
|
+
when "chi", "chi2"
|
102
|
+
chi2_tbl(*opts) do |n, x|
|
103
|
+
mod.pchi2_x(n, x)
|
104
|
+
end
|
105
|
+
when "t"
|
106
|
+
t_tbl(*opts) do |n, x|
|
107
|
+
mod.ptx__x(n, x)
|
108
|
+
end
|
109
|
+
when "f"
|
110
|
+
f_tbl(*opts) do |n1, n2, a|
|
111
|
+
mod.pf_x(n1, n2, a)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
if $0 == __FILE__
|
118
|
+
if ARGV.empty?
|
119
|
+
puts "-- This script makes tables of distributions"
|
120
|
+
puts "Example:"
|
121
|
+
puts " #$0 norm"
|
122
|
+
puts " #$0 chi2"
|
123
|
+
puts " #$0 t"
|
124
|
+
puts " #$0 f 0.01"
|
125
|
+
exit
|
126
|
+
end
|
127
|
+
require "statistics2"
|
128
|
+
show_tbl(Statistics2, *ARGV)
|
129
|
+
end
|