# This class prepares a pretty-print version of a polynomial with a minimum of 2 coefficients
# Create the polynomial object and store the coefficients
raise ArgumentError, "Need at least 2 coefficients" if args.length < 2
@args = args
# Returns a string version of the polynomial, simplifies coefficients of 1x^n to x^n,
# simplifies x^1 to x and ax^0 to a. Doesn't include elements with a coefficient of 0.
# If all coefficients = 0, returns "0".
polynomial = 
@args.each_with_index do |coefficient, index|
polynomial << coefficient.to_s + "x^" + (@args.length - 1 - index).to_s
return polynomial.join("+").gsub(/\+\-/, '-').gsub(/(^|[\+\-])x/, '\1x').gsub("x^1", 'x').gsub("x^0", '')
# ^| in regex handles case where 1x is at beginning of line, otherwise it's -1x and is covered by rest of regex