Sha256: d6aed01eeb6159d7bed981220b9d109987fec20cf48c21ab4277ce57be612979

Contents?: true

Size: 204 Bytes

Versions: 41

Compression:

Stored size: 204 Bytes

Contents

#!/usr/bin/env ruby
# Compute the n'th triangle number - the hard way
# triangle(n) == (n * (n+1)) / 2
def triangle(n)
  tri = 0
  0.upto(n) do |i|
    tri += i
  end
  return tri
 end
 
puts triangle(3)

Version data entries

41 entries across 41 versions & 6 rubygems

Version Path
logstash-output-icinga-1.1.0 vendor/jruby/1.9/gems/debugger-1.6.8/doc/triangle.rb
debugger-1.6.8 doc/triangle.rb
debugger-1.6.7 doc/triangle.rb
debugger-1.6.6 doc/triangle.rb
debugger-1.6.5 doc/triangle.rb
debugger-1.6.4 doc/triangle.rb
debugger-1.6.3 doc/triangle.rb
debugger-1.6.2 doc/triangle.rb
candlepin-api-0.4.0 bundle/ruby/gems/debugger-1.6.1/doc/triangle.rb
debugger-1.6.1 doc/triangle.rb
debugger-1.6.0 doc/triangle.rb
byebug-1.1.1 old_doc/triangle.rb
byebug-1.1.0 old_doc/triangle.rb
byebug-1.0.3 old_doc/triangle.rb
byebug-1.0.2 old_doc/triangle.rb
byebug-1.0.1 old_doc/triangle.rb
byebug-1.0.0 old_doc/triangle.rb
debugger2-1.0.0.beta2 doc/triangle.rb
debugger2-1.0.0.beta1 doc/triangle.rb
byebug-0.0.1 doc/triangle.rb