Sha256: e7937716137278c25d33ad8a0b864d64f23d2ea43880975849df598abd509fbe
Contents?: true
Size: 360 Bytes
Versions: 18
Compression:
Stored size: 360 Bytes
Contents
class Integer def binomial?(exp=4) x = self return true if (0..2).include? x (2..exp).each do |n| (1...x).each do |a| an = a**n sign, *terms = an > x ? [:-, an, x] : [:+, x, an] b = (terms.reduce(:-))**(1.0/n.to_f) return true if b.integer? and x == an.send(sign, b**n) end end false end end
Version data entries
18 entries across 18 versions & 1 rubygems