-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpoeta.rb
More file actions
39 lines (33 loc) · 834 Bytes
/
Copy pathpoeta.rb
File metadata and controls
39 lines (33 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env ruby -wKU
# poeta.rb
# juanfc 2010-04-14
#5000.0 poemas de 8192 caracteres.
#40.628416 segundos.
#123.066574881974 poemas / segundo.
kCuantos= 5e3
kLength= 8192
$ctr= 0
now= Time.now
$words=<<END.downcase.split
Con diez cañones por banda viento en popa a toda vela
no corta el mar si no vuela un velero bergantín bajel
pirata llamado por su bravura el temido en todo el mar
conocido del uno al otro confín
END
def poema(length)
r=""
prev=""
curr=""
while r.length < length do
curr=$words[rand($words.length)] until curr != prev
r+= (prev=curr)+ " "
end
$ctr+=1
return r
end
while $ctr < kCuantos do
poema(kLength)
end
puts(kCuantos.to_s + " poemas de "+ kLength.to_s+ " caracteres.");
puts((now=Time.now - now).to_s + " segundos.");
puts((kCuantos/now).to_s+ " poemas / segundo.");