Sha256: cc0e9e8264068bb21bdb624c87172b6f3dfeed37f7bff09a2feeeb7c17717a35
Contents?: true
Size: 677 Bytes
Versions: 1
Compression:
Stored size: 677 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
congruence_solver-0.3.1 | bench/bench_tools.rb |