summaryrefslogtreecommitdiff
path: root/sample/fact.rb
diff options
context:
space:
mode:
Diffstat (limited to 'sample/fact.rb')
-rw-r--r--sample/fact.rb5
1 files changed, 2 insertions, 3 deletions
diff --git a/sample/fact.rb b/sample/fact.rb
index 1462a69..d8147a4 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