Sha256: 886a8fbfecef9e4837098fedec2fe44353ede410d1facb02f6b343938ed6e83f
Contents?: true
Size: 645 Bytes
Versions: 5
Compression:
Stored size: 645 Bytes
Contents
def polynomial_to_s(coeffs) polynomial = "" is_first_term = true coeffs.reverse.each_with_index do |coe, idx| exp = coeffs.length - idx - 1 if coe != 0 if is_first_term is_first_term = false else if coe < 0 polynomial << " - " else polynomial << " + " end end if coe.abs > 1 or (coe.abs == 1 and exp < 2) polynomial << coe.abs.to_s end if exp > 0 polynomial << "x" if exp > 1 polynomial << "^#{exp}" end end end end polynomial end
Version data entries
5 entries across 5 versions & 1 rubygems