summaryrefslogtreecommitdiff
path: root/sample
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-03-24 08:52:35 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-03-24 08:52:35 +0000
commit35247a52ef719584a59ae9c518523f0ee825c8e3 (patch)
treee14e2a884d3c40a86f93b8dcb4ec144f510fe35a /sample
parent1727010a3abf84fd06f0e44d44b1b8ef6cde588e (diff)
990324
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_3@409 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sample')
-rw-r--r--sample/cal.rb10
-rw-r--r--sample/from.rb2
-rw-r--r--sample/mine.rb2
-rw-r--r--sample/sieve.rb21
4 files changed, 17 insertions, 18 deletions
diff --git a/sample/cal.rb b/sample/cal.rb
index 50865db..c65f7a7 100644
--- a/sample/cal.rb
+++ b/sample/cal.rb
@@ -1,7 +1,7 @@
#! /usr/local/bin/ruby
# cal.rb (bsd compatible version): Written by Tadayoshi Funaba 1998, 1999
-# $Id: bsdcal.rb,v 1.3 1999/02/06 08:52:21 tadf Exp $
+# $Id: bsdcal.rb,v 1.4 1999/03/06 02:05:59 tadf Exp $
require 'date2'
@@ -70,10 +70,10 @@ end
while /^-([^-].*)$/no =~ $*[0]
a = $1
- if /^c(.+)?$/no =~ a then
- if $1 then
+ if /^c(.+)?$/no =~ a
+ if $1
$cc = $1.downcase
- elsif $*.length >= 2 then
+ elsif $*.length >= 2
$cc = $*[1].downcase
$*.shift
else
@@ -109,7 +109,7 @@ end
usage unless m.nil? or (1..12) === m
usage unless y >= -4712
$w = if $jd then 3 else 2 end
-unless $yr then
+unless $yr
print cal(m, y, gs)
else
print y.to_s.center(((($w + 1) * 7) - 1) *
diff --git a/sample/from.rb b/sample/from.rb
index 93b6c4b..c458b4e 100644
--- a/sample/from.rb
+++ b/sample/from.rb
@@ -17,6 +17,8 @@ class String
len += 1
me = self[0, len].ljust(len)
if me =~ /.$/ and $&.size == 2
+ p me[-2..-1]
+ me[-2..-1] = ' '
me[-2, 2] = ' '
end
me.chop!
diff --git a/sample/mine.rb b/sample/mine.rb
index f18d6c6..fd32648 100644
--- a/sample/mine.rb
+++ b/sample/mine.rb
@@ -168,6 +168,6 @@ begin
end
end
ensure
- system("stty -raw echo")
+ system("stty -raw echo")
end
print "\n"
diff --git a/sample/sieve.rb b/sample/sieve.rb
index 5e9f792..359c185 100644
--- a/sample/sieve.rb
+++ b/sample/sieve.rb
@@ -1,17 +1,14 @@
# sieve of Eratosthenes
-sieve = []
max = Integer(ARGV.shift || 100)
+sieve = []
+for i in 2 .. max
+ sieve[i] = i
+end
-print "1"
-for i in 2 .. max
- begin
- for d in sieve
- fail if i % d == 0
- end
- print ", "
- print i
- sieve.push(i)
- rescue
+for i in 2 .. Math.sqrt(max)
+ next unless sieve[i]
+ (i*i).step(max, i) do |j|
+ sieve[j] = nil
end
end
-print "\n"
+puts sieve.compact.join ", "