Improve.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3186 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c37140b351
commit
02a8d06fa8
@ -2,9 +2,9 @@
|
|||||||
# usege: ruby occur2.rb file..
|
# usege: ruby occur2.rb file..
|
||||||
freq = {}
|
freq = {}
|
||||||
while gets()
|
while gets()
|
||||||
for word in $_.split(/\W+/)
|
for word in split(/\W+/)
|
||||||
begin
|
begin
|
||||||
freq[word] = freq[word] + 1
|
freq[word] += 1
|
||||||
rescue NameError
|
rescue NameError
|
||||||
freq[word] = 1
|
freq[word] = 1
|
||||||
end
|
end
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
k, a, b, a1, b1 = 2, 4, 1, 12, 4
|
k, a, b, a1, b1 = 2, 4, 1, 12, 4
|
||||||
|
|
||||||
while TRUE
|
loop do
|
||||||
# Next approximation
|
# Next approximation
|
||||||
p, q, k = k*k, 2*k+1, k+1
|
p, q, k = k*k, 2*k+1, k+1
|
||||||
a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1
|
a, b, a1, b1 = a1, b1, p*a+q*a1, p*b+q*b1
|
||||||
|
@ -8,22 +8,23 @@ w = 20.0 # distance between eyes
|
|||||||
h =1.0 # distance from screen and base plane
|
h =1.0 # distance from screen and base plane
|
||||||
d = 0.2 # z value unit
|
d = 0.2 # z value unit
|
||||||
ss="abcdefghijklmnopqrstuvwxyz0123456789#!$%^&*()-=\\[];'`,./"
|
ss="abcdefghijklmnopqrstuvwxyz0123456789#!$%^&*()-=\\[];'`,./"
|
||||||
rnd = srand()
|
rnd = srand() # You don't actually need this in ruby - srand() is called
|
||||||
|
# on the first call of rand().
|
||||||
|
|
||||||
while gets()
|
while gets()
|
||||||
# print($_)
|
# print($_)
|
||||||
xr = -hdw; y = h * 1.0; maxxl = -999
|
xr = -hdw; y = h * 1.0; maxxl = -999
|
||||||
s = "";
|
s = ""
|
||||||
while xr < hdw
|
while xr < hdw
|
||||||
x = xr * (1 + y) - y * w / 2
|
x = xr * (1 + y) - y * w / 2
|
||||||
i = (x / (1 + h) + sw / 2)
|
i = (x / (1 + h) + sw / 2)
|
||||||
if (1 < i && i < $_.length);
|
if (1 < i && i < $_.length)
|
||||||
c = $_[i, 1].to_i
|
c = $_[i, 1].to_i
|
||||||
else
|
else
|
||||||
c = 0
|
c = 0
|
||||||
end
|
end
|
||||||
y = h - d * c
|
y = h - d * c
|
||||||
xl = xr - w * y / (1 + y);
|
xl = xr - w * y / (1 + y)
|
||||||
if xl < -hdw || xl >= hdw || xl <= maxxl
|
if xl < -hdw || xl >= hdw || xl <= maxxl
|
||||||
tt = rand(ss.length)
|
tt = rand(ss.length)
|
||||||
c = ss[tt, 1]
|
c = ss[tt, 1]
|
||||||
@ -36,14 +37,3 @@ while gets()
|
|||||||
end
|
end
|
||||||
print(s, "\n")
|
print(s, "\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,4 +5,4 @@ system(cmd)
|
|||||||
e = Time.now
|
e = Time.now
|
||||||
ut, st, cut, cst = Time.times.to_a
|
ut, st, cut, cst = Time.times.to_a
|
||||||
total = (e - b).to_f
|
total = (e - b).to_f
|
||||||
printf STDERR, "%11.1f real %11.1f user %11.1f sys\n", total, cut, cst
|
STDERR.printf "%11.1f real %11.1f user %11.1f sys\n", total, cut, cst
|
||||||
|
@ -5,7 +5,7 @@ path = ENV['PATH'].split(File::PATH_SEPARATOR)
|
|||||||
for dir in path
|
for dir in path
|
||||||
if File.directory?(dir)
|
if File.directory?(dir)
|
||||||
for f in d = Dir.open(dir)
|
for f in d = Dir.open(dir)
|
||||||
fpath = dir+"/"+f
|
fpath = File.join(dir, f)
|
||||||
if File.file?(fpath) && (File.stat(fpath).mode & 022) != 0
|
if File.file?(fpath) && (File.stat(fpath).mode & 022) != 0
|
||||||
printf("file %s is writable from other users\n", fpath)
|
printf("file %s is writable from other users\n", fpath)
|
||||||
end
|
end
|
||||||
|
@ -8,11 +8,11 @@ addr = gs.addr
|
|||||||
addr.shift
|
addr.shift
|
||||||
printf("server is on %s\n", addr.join(":"))
|
printf("server is on %s\n", addr.join(":"))
|
||||||
|
|
||||||
while TRUE
|
loop do
|
||||||
Thread.start(gs.accept) do |s|
|
Thread.start(gs.accept) do |s|
|
||||||
print(s, " is accepted\n")
|
print(s, " is accepted\n")
|
||||||
while s.gets
|
while line = s.gets
|
||||||
s.write($_)
|
s.write(line)
|
||||||
end
|
end
|
||||||
print(s, " is gone\n")
|
print(s, " is gone\n")
|
||||||
s.close
|
s.close
|
||||||
|
Loading…
x
Reference in New Issue
Block a user