diff options
author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-12-19 20:42:50 +0000 |
---|---|---|
committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2002-12-19 20:42:50 +0000 |
commit | 63406c49712703ca63d610e75bba4ed0078c0f16 (patch) | |
tree | df1d1c9084747f774a22748f755ae7aea891e4c2 /sample/fact.rb | |
parent | 354af9da36eaeec70d4fdaddab78a8ecb11101a0 (diff) | |
download | ruby-63406c49712703ca63d610e75bba4ed0078c0f16.tar.gz |
Improve.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3184 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sample/fact.rb')
-rw-r--r-- | sample/fact.rb | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/sample/fact.rb b/sample/fact.rb index 1462a6923a..d8147a40f1 100644 --- a/sample/fact.rb +++ b/sample/fact.rb @@ -1,9 +1,8 @@ def fact(n) return 1 if n == 0 f = 1 - while n>0 - f *= n - n -= 1 + n.downto(1) do |i| + f *= i end return f end |