Skip to content

Commit c830fa4

Browse files
authored
Merge pull request #43 from pain11/master
Geometric progression in ruby
2 parents fd0bf20 + b83af61 commit c830fa4

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

math/geometric_progression.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def geometric_progression initial, ratio, numbers
2+
(numbers - 1).times.inject([initial]){|array| array << array.last * ratio}
3+
end
4+
5+
puts "geometric_progression(2, 2, 10): #{geometric_progression(2, 2, 10)}"
6+
puts "geometric_progression(2, 0.5, 10): #{geometric_progression(2, 0.5, 10)}"

0 commit comments

Comments
 (0)