Sha256: 1267c55a16f14e9173108467b61cf93d356067b4163636a8cecec4d71cca8a18

Contents?: true

Size: 304 Bytes

Versions: 5

Compression:

Stored size: 304 Bytes

Contents

# coding: utf-8
class Integer
  def super_catalan
    n = self
    return 1 if n <= 2
    Rational(
      3 * ((2 * n) - 3) * (n - 1).super_catalan - (n - 3) * (n - 2).super_catalan,
      n
    ).to_i
  end

  memoize :super_catalan

  def super_catalan?
    in_sequence?(seq: :super_catalan)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
numb-0.186.0 lib/numb/super_catalan.rb
numb-0.185.0 lib/numb/super_catalan.rb
numb-0.184.0 lib/numb/super_catalan.rb
numb-0.181.0 lib/numb/super_catalan.rb
numb-0.170.0 lib/numb/super_catalan.rb