rubylabs 0.6.2 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ begin
11
11
  gem.email = "conery@cs.uoregon.edu"
12
12
  gem.homepage = "http://github.com/conery/rubylabs"
13
13
  gem.authors = ["conery"]
14
- gem.files = FileList['[A-Z]*', 'lib/**/*.rb', 'data/**', 'bin/**/*.rb']
14
+ gem.files = FileList['[A-Z]*', 'lib/**/*.rb', 'data/*', 'data/mars/*', 'data/eliza/*', 'bin/**/*.rb']
15
15
  gem.test_files = FileList['test/**/*.rb']
16
16
  gem.rubyforge_project = "rubylabs"
17
17
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.2
1
+ 0.6.4
@@ -0,0 +1,357 @@
1
+ # The "Doctor" script for ELIZA. These rules follow the general
2
+ # outline of original rules from Joseph Weizenbaum's CACM paper, but
3
+ # there are a few differences.
4
+
5
+ :start "How do you do. Please tell me your problem."
6
+ :stop "Goodbye."
7
+
8
+ :default $noncommittal
9
+
10
+ $noncommittal
11
+ /.*/
12
+ "I am not sure I understand you fully."
13
+ "Please go on."
14
+ "What does that suggest to you?"
15
+ "Do you feel strongly about discussing such things?"
16
+
17
+ # The preprocessor turns "can't" into "can not", etc. That means some of the
18
+ # rule patterns look strange (e.g. /why can not i (.*)/) but they match inputs
19
+ # that have contractions and the responses are OK.
20
+
21
+ :pre don't "do not"
22
+ :pre can't "can not"
23
+ :pre won't "will not"
24
+ :pre i'm "I am"
25
+ :pre you're "you are"
26
+
27
+ :post me "you"
28
+ :post i "you"
29
+ :post you "I"
30
+ :post am "are"
31
+ :post are "am"
32
+ :post myself "yourself"
33
+ :post yourself "myself"
34
+ :post my "your"
35
+ :post your "my"
36
+
37
+ sorry
38
+ /.*/
39
+ "Please don't apologize."
40
+ "Apologies are not necessary."
41
+ "What feelings do you have when you apologize?"
42
+ "I've told you that apologies are not required."
43
+
44
+ remember 5
45
+ /I remember (.*)/
46
+ "Do you often think of $1?"
47
+ "Does thinking of $1 bring anything else to mind?"
48
+ "What else do you remember?"
49
+ "Why do you remember $1 just now?"
50
+ "What is the connection between me and $1?"
51
+ /do you remember (.*)/
52
+ "Did you think I would forget $1?"
53
+ "Why do you think I should recall $1 now?"
54
+ "What about $1?"
55
+ "You mentioned $1."
56
+ @$what
57
+
58
+ if 3
59
+ /if (.*)/
60
+ "Do you think its likely that $1?"
61
+ "Do you wish that $1?"
62
+ "What do you think about $1?"
63
+ "Really, if $1?"
64
+
65
+ :alias $dreamt dreamed dreamt
66
+ $dreamt 4
67
+ /I ($dreamt) (.*)/
68
+ "Really, $2?"
69
+ "Have you ever fantasized $2 while you were awake?"
70
+ "Have you $1 $2 before?"
71
+ @$dream
72
+
73
+ :alias $dream dream dreams
74
+ $dream 3
75
+ /.*/
76
+ "What does that dream suggest to you?"
77
+ "Do you dream often?"
78
+ "What persons appear in your dreams?"
79
+ "Don't you believe that dream has something to do with your problem?"
80
+
81
+ certainly
82
+ /.*/
83
+ @yes
84
+
85
+ perhaps
86
+ /.*/
87
+ "You don't seem quite certain."
88
+ "Why the uncertain tone?"
89
+ "Can't you be more positive?"
90
+ "You aren't sure?"
91
+ "Don't you know?"
92
+
93
+ maybe
94
+ /.*/
95
+ @perhaps
96
+
97
+ :alias $name name named names
98
+
99
+ $name 15
100
+ /.*/
101
+ "I am not interested in names."
102
+ "I've told you before, I don't care about names - please continue."
103
+
104
+ :alias $language deutsch francais italiano espanol
105
+ $language
106
+ /($language)/
107
+ "I'm sorry, I don't speak $1."
108
+ "I'm sorry, I speak only English."
109
+
110
+ hello
111
+ /.*/
112
+ "How do you do? Please state your problem."
113
+
114
+ :alias $computer computer computers machine machines
115
+ $computer 50
116
+ /(computer|machine)s?/
117
+ "Do $1s worry you?"
118
+ "Why do you mention $1s?"
119
+ "What do you think $1s have to do with your problem?"
120
+ "Don't you think $1s can help people?"
121
+ "What about $1s worries you?"
122
+ "What do you think about $1s?"
123
+
124
+ are
125
+ /are you (.*)/
126
+ "Why are you interested in whether I am $1 or not?"
127
+ "Would you prefer if I weren't $1?"
128
+ "Perhaps I am $1 in your fantasies?"
129
+ "Do you sometimes think I am $1?"
130
+ @$what
131
+ /you are (.*)/
132
+ "What makes you think I am $1?"
133
+ "Do you sometimes wish you were $1?"
134
+ "Perhaps you would like to be $1?"
135
+ /are (.*)/
136
+ "Did you think they might not be $1?"
137
+ "Would you like it if they were not $1?"
138
+ "What if they were not $1?"
139
+ "Possibly they are $1?"
140
+
141
+ your
142
+ /your (.*)/
143
+ "Why are you concerned over my $1?"
144
+ "What about your own $1?"
145
+ "Are you worried about someone else's $1?"
146
+ "Really, my $1?"
147
+
148
+ was 2
149
+ /was i (.*)/
150
+ "What if you were $1?"
151
+ "Do you think you were $1?"
152
+ "Were you $1?"
153
+ "What would it mean if you were $1?"
154
+ "What does '$1' suggest to you?"
155
+ @$what
156
+ /i was (.*)/
157
+ "Were you really?"
158
+ "Why do you tell me you were $1 now?"
159
+ "Perhaps I already knew you were $1?"
160
+
161
+ were
162
+ /were you (.*)/
163
+ "Would you like to believe I was $1?"
164
+ "What suggests that I was $1?"
165
+ "What do you think?"
166
+ "Perhaps I was $1?"
167
+ "What if I had been $1?"
168
+
169
+ :alias $belief believe feel think wish
170
+
171
+ i
172
+ /i (want|need) (.*)/
173
+ "What would it mean to you if you got $2?"
174
+ "Why do you $1 $2?"
175
+ "Suppose you got $2 soon?"
176
+ "What if you never got $2?"
177
+ "What would getting $2 mean to you?"
178
+ "What does $1ing $2 have to do with this discussion?"
179
+ /i am (.*)(sad|unhappy|depressed|sick)(.*)/
180
+ "I am sorry to hear you are $2$3."
181
+ "Do you think coming here will help you not to be $2$3?"
182
+ "I'm sure its not pleasant to be $2$3."
183
+ "Can you explain what made you $2$3?"
184
+ /i am (.*)(happy|elated|glad|better)(.*)/
185
+ "How have I helped you to be $2$3?"
186
+ "Has your treatment made you $2$3?"
187
+ "What makes you $2$3 just now?"
188
+ "Can you explain why you are suddenly $2$3?"
189
+ /am i (.*)/
190
+ "Do you believe you are $1?"
191
+ "Would you want to be $1?"
192
+ "You wish I would tell you you are $1?"
193
+ "What would it mean if you were $1?"
194
+ @$what
195
+ /i was/
196
+ @was
197
+ /i ($belief) i (.*)/
198
+ "Do you really think so?"
199
+ "But you are not sure you $2?"
200
+ "Do you really doubt you $2"
201
+ /i .*($belief).* you/
202
+ @you
203
+ /i am (.*)/
204
+ "Is it because you are $1 that you came to me?"
205
+ "How long have you been $1?"
206
+ "Do you believe it normal to be $1?"
207
+ "Do you enjoy being $1?"
208
+ /i (can not|cannot) (.*)/
209
+ "How do you know you can't $2?"
210
+ "Have you tried?"
211
+ "Perhaps you could $2 now?"
212
+ "Do you really want to be able to $2?"
213
+ /can i (.*)/
214
+ "Whether or not you can $1 depends on you more than on me."
215
+ "Do you want to be able to $1?"
216
+ "Perhaps you don't want to $1."
217
+ @$what
218
+ /why can not i (.*)/
219
+ "Do you think you should be able to $1?"
220
+ "Do you want to be able to $1?"
221
+ "Do you believe this will help you to $1?"
222
+ "Have you any idea why you can't $1?"
223
+ @$what
224
+ /i do not (.*)/
225
+ "Don't you really $1?"
226
+ "Why don't you $1?"
227
+ "Do you wish to be able to $1?"
228
+ "Does that trouble you?"
229
+ /i feel (.*)/
230
+ "Tell me more about such feelings."
231
+ "Do you often feel $1?"
232
+ "Do you enjoy feeling $1?"
233
+ "Of what does feeling $1 remind you?"
234
+ /i (.*) you/
235
+ "Perhaps in your fantasy we $1 each other?"
236
+ "Do you wish to $1 me?"
237
+ "You seem to need to $1 me."
238
+ "Do you $1 anyone else?"
239
+ /(.*)/
240
+ "You say '$1'?"
241
+ "Can you elaborate on that?"
242
+ "Do you say '$1' for some special reason?"
243
+ "That's quite interesting."
244
+
245
+ you
246
+ /you remind me of/
247
+ @$dit
248
+ /you (.*) me/
249
+ "Why do you think I $1 you?"
250
+ "You like to think I $1 you, don't you?"
251
+ "What makes you think I $1 you?"
252
+ "Really, I $1 you?"
253
+ "Do you wish to believe I $1 you?"
254
+ "Suppose I did $1 you; what would that mean?"
255
+ "Does someone else believe I $1 you?"
256
+ /can you (.*)/
257
+ "You believe I can $1, don't you?"
258
+ @$what
259
+ "You want me to be able to $1?"
260
+ "Perhaps you would like to be able to $1 yourself?"
261
+ /why do not you (.*)/
262
+ "Do you believe I don't $1?"
263
+ "Perhaps I will $1 in good time."
264
+ "Should you $1 yourself?"
265
+ "You want me to $1?"
266
+ @$what
267
+ /you (.*)/
268
+ "We were discussing you, not me."
269
+ "Oh, I $1?"
270
+ "You're not really talking about me, are you?"
271
+ "What are your feelings now?"
272
+
273
+ yes
274
+ /.*/
275
+ "You seem quite positive."
276
+ "You are sure?"
277
+ "I see."
278
+ "I understand."
279
+
280
+ no
281
+ /.*/
282
+ "Are you saying 'no' just to be negative?"
283
+ "You are being a bit negative."
284
+ "Why not?"
285
+ "Why 'no'?"
286
+
287
+ :alias $family mother mom father dad sister brother wife husband partner child children
288
+
289
+ my 2
290
+ /my (.*)($family) (.*)/
291
+ "Tell me more about your family."
292
+ "Who else in your family $3?"
293
+ "Your $2?"
294
+ "What else comes to mind when you think of your $2?"
295
+ /my (.*)/
296
+ "Your $1?"
297
+ "Why do you say your $1?"
298
+ "Does that suggest anything else which belongs to you?"
299
+ "Is it important to you that $1?"
300
+
301
+ :alias $what what how when
302
+
303
+ $what
304
+ /.*/
305
+ "Why do you ask?"
306
+ "Does that question interest you?"
307
+ "What is it you really want to know?"
308
+ "Are such questions much on your mind?"
309
+ "What answer would please you most?"
310
+ "What do you think?"
311
+ "What comes to your mind when you ask that?"
312
+ "Have you asked such questions before?"
313
+ "Have you asked anyone else?"
314
+
315
+ because
316
+ /.*/
317
+ "Is that the real reason?"
318
+ "Don't any other reasons come to mind?"
319
+ "Does that reason seem to explain anything else?"
320
+ "What other reasons might there be?"
321
+
322
+ :alias $everyone everyone everybody nobody noone
323
+
324
+ $everyone 2
325
+ /($everyone) (.*)/
326
+ "Really, $1 $2?"
327
+ "Surely not $1 $2?"
328
+ "Can you think of anyone in particular?"
329
+ "Who, for example?"
330
+ "You are thinking of a very special person?"
331
+ "Who, may I ask?"
332
+ "Someone special perhaps?"
333
+ "You have a particular person in mind, don't you?"
334
+ "Who do you think you're talking about?"
335
+
336
+ always 2
337
+ /.*/
338
+ "Can you think of a specific example?"
339
+ "When?"
340
+ "What incident are you thinking of?"
341
+ "Really, always?"
342
+
343
+ like 10
344
+ /(am|is|are|was).*like/
345
+ @$dit
346
+
347
+ :alias $dit alike same
348
+ $dit 10
349
+ /.*/
350
+ "In what way?"
351
+ "What resemblance do you see?"
352
+ "What does that similarity suggest to you?"
353
+ "What other connections do you see?"
354
+ "What do you suppose that resemblance means?"
355
+ "What is the connection, do you suppose?"
356
+ "Could there really be some connection?"
357
+ "How?"
@@ -0,0 +1,18 @@
1
+ ;redcode
2
+ ;name Chang1
3
+ ;author Morrison J. Chang
4
+ ;strategy 2nd place in ICWST'86
5
+ ;strategy dwarf, imp-stomper, imp-gun
6
+ ;assert 1
7
+ MOV #0 ,-1
8
+ JMP -1
9
+ DAT #9
10
+ START SPL -2
11
+ SPL 4
12
+ ADD #-16 ,-3
13
+ MOV #0 ,@-4
14
+ JMP -4
15
+ SPL 2
16
+ JMP -1
17
+ MOV 0 ,1
18
+ END START
@@ -0,0 +1,11 @@
1
+ ;redcode verbose
2
+ ;name Dwarf
3
+ ;author A. K. Dewdney
4
+ ;strategy Throw DAT bombs (as in "fetchez la vache") around memory, hitting every 4th memory cell.
5
+ ;strategy This program was presented in the first Corewar article.
6
+
7
+ vache DAT #0
8
+ dwarf ADD #4, vache
9
+ MOV vache, @vache
10
+ JMP dwarf
11
+ end dwarf
@@ -0,0 +1,18 @@
1
+ ;redcode
2
+ ;name Ferret
3
+ ;author Robert R. Reed III
4
+ ;strategy 1st place in ICWST'87
5
+ ;assert 1
6
+ START MOV #4908 ,B
7
+ F CMP <A ,<B
8
+ MOV S ,@B
9
+ CMP <A ,<B
10
+ A MOV S ,-5
11
+ DJN F ,B
12
+ K MOV W ,<W
13
+ DJN K ,<W
14
+ ADD #3 ,W
15
+ B JMP K
16
+ W DAT #-10
17
+ S SPL 0
18
+ END START
data/data/mars/imp.txt ADDED
@@ -0,0 +1,6 @@
1
+ ;redcode
2
+ ;name Imp
3
+ ;author A. K. Dewdney
4
+ ;strategy This program was presented in the first Corewar article.
5
+ ;assert 1
6
+ mov 0, 1
@@ -0,0 +1,15 @@
1
+ ;redcode
2
+ ;name Mice
3
+ ;author Chip Wendell
4
+ ;strategy 1st place in ICWST'86
5
+ ;strategy replicator
6
+ ;assert 1
7
+ PTR DAT #0
8
+ START MOV #12 ,PTR
9
+ LOOP MOV @PTR ,<COPY
10
+ DJN LOOP ,PTR
11
+ SPL @COPY ,0
12
+ ADD #653 ,COPY
13
+ JMZ START ,PTR
14
+ COPY DAT #833
15
+ END START
@@ -0,0 +1,10 @@
1
+ ;redcode
2
+ ;name Midget
3
+ ;author Chip Wendell
4
+ ;strategy 3rd place in ICWST'86
5
+ ;assert 1
6
+ START ADD #-28 ,3
7
+ MOV #0 ,@2
8
+ JMP -2
9
+ DAT #-980
10
+ END START
@@ -0,0 +1,36 @@
1
+ ;redcode
2
+ ;name Piper
3
+ ;author Chip Wendell
4
+ ;strategy 3rd place in ICWST'87
5
+ ;strategy vampire -> clear
6
+ ;assert 1
7
+ START ADD #65 ,BAIT
8
+ LURE MOV BAIT ,@TARGET
9
+ ADD #48 ,BAIT
10
+ SUB #48 ,TARGET
11
+ JMN LURE ,TARGET
12
+ SET MOV #-12 ,PTR
13
+ BOMB MOV PTR ,@PTR
14
+ DJN BOMB ,PTR
15
+ JMP SET
16
+ BAIT JMP @0
17
+ TARGET DAT #-48
18
+ PTR DAT #-12
19
+ DAT #0
20
+ DAT #0
21
+ DAT #0
22
+ DAT #0
23
+ DAT #0
24
+ DAT #0
25
+ DAT #0
26
+ DAT #0
27
+ DAT #0
28
+ DAT #0
29
+ DAT #0
30
+ DAT #0
31
+ DAT #0
32
+ DAT #0
33
+ DAT #0
34
+ TRAP SPL 0
35
+ JMP TRAP
36
+ END
@@ -0,0 +1,24 @@
1
+ ;redcode
2
+ ;name Plague
3
+ ;author Ron Paludan
4
+ ;strategy 2nd place in ICWST'87
5
+ ;assert 1
6
+ SPL WIPE
7
+ SPL WIPE
8
+ LOOP ADD #24 ,PTR
9
+ JMZ LOOP ,@PTR
10
+ MOV JBOMB ,@PTR
11
+ MOV SBOMB ,<PTR
12
+ ADD #1 ,PTR
13
+ JMP LOOP
14
+ DAT #1
15
+ DAT #2
16
+ DAT #3
17
+ DAT #4
18
+ PTR DAT #5
19
+ WIPE MOV 2 ,<2
20
+ JMP WIPE
21
+ DAT #-16
22
+ JBOMB JMP -1
23
+ SBOMB SPL 0
24
+ END
@@ -0,0 +1,20 @@
1
+ ;redcode
2
+ ;name Celsius
3
+ ;strategy cels = (fahr - 32) * 5 / 9
4
+
5
+ fahr DAT #80 ; input temperature
6
+ cels DAT #0 ; store result here
7
+ ftmp DAT #0 ; save fahr-32 here
8
+ start MOV fahr, ftmp ; (1) subtract 32
9
+ SUB #32, ftmp
10
+ mult ADD ftmp, acc ; (2) multiply by 5
11
+ SUB #1, count
12
+ JMN mult, count
13
+ div SUB #9, acc ; (3) divide by 9
14
+ SLT #0, acc
15
+ DAT #0 ; stop here when division done
16
+ ADD #1, cels
17
+ JMP div
18
+ acc DAT #0 ; accumulator
19
+ count DAT #5 ; counter
20
+ end start
@@ -0,0 +1,13 @@
1
+ ;redcode
2
+ ;name div
3
+ ;strategy division demo -- compute 20 / 9
4
+
5
+ x DAT #20
6
+ y DAT #9
7
+ count DAT #0 ; result goes here
8
+ div SUB y, x
9
+ SLT #0, x
10
+ DAT #0 ; stop here when division done
11
+ ADD #1, count
12
+ JMP div
13
+ end div
@@ -0,0 +1,7 @@
1
+ ; test_hello.txt -- a "hello, world" program for MARS
2
+
3
+ x DAT #7
4
+ y DAT #4
5
+ hello ADD x, y ; add the contents of x to y
6
+ DAT #0 ; a dat instruction halts the machine
7
+ end hello
@@ -0,0 +1,12 @@
1
+ ;redcode
2
+ ;name mult
3
+ ;strategy multiplication demo: compute acc = x * y
4
+
5
+ x DAT #7 ; multiplicand
6
+ y DAT #6 ; multiplier
7
+ acc DAT #0 ; accumulator -- result goes here
8
+ mult ADD x, acc ; add x to acc
9
+ SUB #1, y ; subtract 1 from y
10
+ JMN mult, y ; repeat if y is not 0
11
+ DAT #0 ; algorithm halts here
12
+ end mult
@@ -0,0 +1,8 @@
1
+ ;redcode
2
+ ;name threads
3
+ ;strategy launch imps to demonstrate how SPL works
4
+
5
+ start SPL imp
6
+ JMP start
7
+ imp MOV 0, 1
8
+ end start
data/lib/bitlab.rb CHANGED
@@ -584,41 +584,3 @@ class Fixnum
584
584
 
585
585
  end
586
586
 
587
- =begin rdoc
588
- Priority queue class -- simple wrapper for an array that can only be updated via
589
- +<<+ and +shift+ operations. Also responds to +length+, +first+, and +last+,
590
- and allows direct access to an item through an index expression, but does not allow
591
- assignment via an index or any other array operation.
592
- The +<<+ method checks to make sure an object is comparable (responds to <) before
593
- adding it to the queue.
594
- =end
595
-
596
-
597
- # Note: defined outside rubylabs, so it's a top level class -- move to own file, require here?
598
-
599
- class PriorityQueue
600
-
601
- def initialize
602
- @q = Array.new
603
- end
604
-
605
- def <<(obj)
606
- raise "Object cannot be inserted into priority queue" unless obj.respond_to?(:<)
607
- i = 0
608
- while (i < @q.length)
609
- break if obj < @q[i]
610
- i += 1
611
- end
612
- @q.insert(i, obj)
613
- end
614
-
615
- %w{shift length first last to_s inspect}.each do |name|
616
- eval "def #{name}() @q.#{name} end"
617
- end
618
-
619
- def [](i)
620
- @q[i]
621
- end
622
-
623
- end # PriorityQueue
624
-