rubylabs 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/bin/{lab_setup.rb → lab-setup.rb} +1 -2
- data/data/tsp/ireland.txt +3 -3
- data/lib/demos.rb +30 -0
- data/lib/sievelab.rb +0 -1
- data/lib/tsplab.rb +4 -2
- data/test/sieve_test.rb +6 -2
- metadata +5 -16
- data/bin/bb.rb +0 -12
- data/bin/statistics2-0.53/ext/extconf.rb +0 -11
- data/bin/statistics2-0.53/ext/show.rb +0 -11
- data/bin/statistics2-0.53/ext/t.rb +0 -46
- data/bin/statistics2-0.53/mklist.rb +0 -26
- data/bin/statistics2-0.53/sample-tbl.rb +0 -129
- data/bin/statistics2-0.53/statistics2.rb +0 -532
- data/bin/statistics2-0.53/t-inv.rb +0 -54
- data/bin/statistics2.rb +0 -532
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.8.
|
1
|
+
0.8.2
|
data/data/tsp/ireland.txt
CHANGED
data/lib/demos.rb
CHANGED
@@ -134,7 +134,37 @@ module Demos
|
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
137
|
+
=begin rdoc
|
138
|
+
Demonstrate modifiers and if statements
|
139
|
+
=end
|
137
140
|
|
141
|
+
def compound_names(a)
|
142
|
+
a.each { |s| puts s if s.include?(" ") }
|
143
|
+
end
|
144
|
+
|
145
|
+
def emphasize(s)
|
146
|
+
if s == "red" || s == "green" || s == "blue"
|
147
|
+
s.upcase!
|
148
|
+
s += "S"
|
149
|
+
end
|
150
|
+
return s
|
151
|
+
end
|
152
|
+
|
153
|
+
def drink_cup(n)
|
154
|
+
if n == 12
|
155
|
+
return "tall"
|
156
|
+
elsif n == 16
|
157
|
+
return "grande"
|
158
|
+
elsif n == 20
|
159
|
+
return "venti"
|
160
|
+
else
|
161
|
+
return n.to_s + " ounce"
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
def make_order(size, kind)
|
166
|
+
puts "I'll have a " + drink_cup(size) + " " + kind + ", please."
|
167
|
+
end
|
138
168
|
|
139
169
|
end # Demos
|
140
170
|
|
data/lib/sievelab.rb
CHANGED
data/lib/tsplab.rb
CHANGED
@@ -90,10 +90,12 @@ module TSPLab
|
|
90
90
|
|
91
91
|
def make_tour(*args)
|
92
92
|
begin
|
93
|
-
|
93
|
+
args << :any if args.length == 0
|
94
94
|
case args[0]
|
95
|
+
when :any
|
96
|
+
tour = Tour.new(self, labels) # note labels returns clone of @labels array...
|
95
97
|
when :random
|
96
|
-
tour = Tour.new(self, permute!(labels))
|
98
|
+
tour = Tour.new(self, permute!(labels))
|
97
99
|
when :mutate
|
98
100
|
raise "usage" unless args.length >= 2 && args[1].class == Tour && (args[2].nil? || args[2].class == Fixnum)
|
99
101
|
child = args[1].clone
|
data/test/sieve_test.rb
CHANGED
@@ -19,12 +19,16 @@ class TestSieve < Test::Unit::TestCase
|
|
19
19
|
|
20
20
|
# Check length of list generated by sieve with expected number of primes (also from Wikipedia).
|
21
21
|
# pi[i] is the number of primes less than 10**i. Note: calling sieve(n) with n less than 2
|
22
|
-
#
|
22
|
+
# raises an exception ("NoMethodError: undefined method `<' for nil:NilClass")
|
23
23
|
|
24
24
|
def test_02_pi
|
25
25
|
pi = [0, 4, 25, 168, 1229] # 9592
|
26
|
-
for i in
|
26
|
+
for i in 1..(pi.length-1)
|
27
27
|
assert_equal pi[i], sieve(10**i).length
|
28
28
|
end
|
29
29
|
end
|
30
|
+
|
31
|
+
def test_03_error
|
32
|
+
assert_raise(NoMethodError) { sieve(1) }
|
33
|
+
end
|
30
34
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubylabs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- conery
|
@@ -9,16 +9,14 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
13
|
-
default_executable:
|
12
|
+
date: 2010-09-27 00:00:00 -07:00
|
13
|
+
default_executable: lab-setup.rb
|
14
14
|
dependencies: []
|
15
15
|
|
16
16
|
description: A set of modules for interactive experiments in an introductory computer science class.
|
17
17
|
email: conery@cs.uoregon.edu
|
18
18
|
executables:
|
19
|
-
-
|
20
|
-
- lab_setup.rb
|
21
|
-
- statistics2.rb
|
19
|
+
- lab-setup.rb
|
22
20
|
extensions: []
|
23
21
|
|
24
22
|
extra_rdoc_files:
|
@@ -29,16 +27,7 @@ files:
|
|
29
27
|
- README.rdoc
|
30
28
|
- Rakefile
|
31
29
|
- VERSION
|
32
|
-
- bin/
|
33
|
-
- bin/lab_setup.rb
|
34
|
-
- bin/statistics2-0.53/ext/extconf.rb
|
35
|
-
- bin/statistics2-0.53/ext/show.rb
|
36
|
-
- bin/statistics2-0.53/ext/t.rb
|
37
|
-
- bin/statistics2-0.53/mklist.rb
|
38
|
-
- bin/statistics2-0.53/sample-tbl.rb
|
39
|
-
- bin/statistics2-0.53/statistics2.rb
|
40
|
-
- bin/statistics2-0.53/t-inv.rb
|
41
|
-
- bin/statistics2.rb
|
30
|
+
- bin/lab-setup.rb
|
42
31
|
- data/arrays/cars.txt
|
43
32
|
- data/arrays/colors.txt
|
44
33
|
- data/arrays/fruit.txt
|
data/bin/bb.rb
DELETED
@@ -1,12 +0,0 @@
|
|
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
|
@@ -1,11 +0,0 @@
|
|
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
|
@@ -1,46 +0,0 @@
|
|
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"
|
@@ -1,26 +0,0 @@
|
|
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
|
@@ -1,129 +0,0 @@
|
|
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
|