Sha256: 05308c01130b4f9b867d52e5cb7183232f95d2e769fa0dabc0f740d3485da34c

Contents?: true

Size: 201 Bytes

Versions: 15

Compression:

Stored size: 201 Bytes

Contents

class Integer
  def n_gonal?(n)
    raise ArgumentError unless n.is_a?(Integer) and n >= 3
    return true if zero?
    ((Math.sqrt((8*n - 16)*self + (n-4)**2) + n - 4) / (2*n - 4)).integer?
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
numb-0.152.0 lib/numb/n_gonal.rb
numb-0.138.0 lib/numb/n_gonal.rb
numb-0.125.0 lib/numb/n_gonal.rb
numb-0.114.0 lib/numb/n_gonal.rb
numb-0.111.0 lib/numb/n_gonal.rb
numb-0.109.0 lib/numb/n_gonal.rb
numb-0.99.0 lib/numb/n_gonal.rb
numb-0.96.0 lib/numb/n_gonal.rb
numb-0.89.0 lib/numb/n_gonal.rb
numb-0.84.0 lib/numb/n_gonal.rb
numb-0.77.0 lib/numb/n_gonal.rb
numb-0.72.1 lib/numb/n_gonal.rb
numb-0.72.0 lib/numb/n_gonal.rb
numb-0.68.0 lib/numb/n_gonal.rb
numb-0.63.0 lib/numb/n_gonal.rb