Skip to content

Instantly share code, notes, and snippets.

RubyLearning Git & GitHub Course RLGGHC

Block or report user

Report or block RLGGHC

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View RPCFN4_-_Pretty_Polynomial.rb
class Polynomial
def initialize(coeffs)
raise ArgumentError.new("Need at least 2 coefficients.") if coeffs.size < 2
@coeffs = coeffs
end
def to_s
output = []
coeffs = @coeffs.dup
View polynomial.rb
class Polynomial
def initialize(coefs)
if coefs.nil? || !coefs.kind_of?(Array) || coefs.size < 2
raise ArgumentError, "Need at least 2 coefficients."
end
@coefs = coefs
end
View polynomial.rb
#!/usr/bin/ruby
class Polynomial
def initialize(coefficients)
if coefficients.length < 2
raise ArgumentError, 'Need at least 2 coefficients.'
end
order = coefficients.length - 1
@poly = ""
View polynomial.rb
class Polynomial
def initialize(polynomial)
if polynomial.length < 2
raise ArgumentError.new("Need at least 2 coefficients")
else
@polynomial = []
polynomial.reverse.each_with_index do |x, i|
@polynomial << Term.new(x, i, (i == (polynomial.size - 1)))
end
end
View polynomial.rb
class Polynomial
def initialize array
if array.length <= 1
raise ArgumentError.new('Need at least 2 coefficients')
exit
else
@return_string = ''
View polynomial.rb
# Submission for http://rubylearning.com/blog/2009/11/26/rpcfn-rubyfun-4/
# Author: Rohit Arondekar
# Author-URL: http://rohitarondekar.com
# Author-email: hello@rohitarondekar.com
# Notes:
# 1. Storing whether a term is the 1st non zero term as bool in the term
# 2. Added a unit test in polynomial_test.rb
class Polynomial
View rpcfn4.rb
class Polynomial
def initialize args=[]
raise ArgumentError, "Need at least 2 coefficients." if args.size < 2
@max_exp = args.size - 1
@poly = ""
args.each_with_index do |coef, index|
# Code reading 101 : 'coef' stands for 'coefficient'.
next if coef.zero?
@coef = coef
View polynomial.rb
#!/usr/bin/env ruby
# --*-- encoding: UTF-8 --*--
# RPCFN: Ruby Fun (#4)
# @author 梁智敏(Gimi Liang) liang.gimi at gmail dot com
class Polynomial
# Creates a new polynomial.
# @override
# @param [Array<Integer>] coefficients
View polynomial.rb
class Polynomial
def initialize(coefficients)
@coefficients = coefficients
@highest_exponent = coefficients.size-1
raise ArgumentError, 'Need at least 2 coefficients' if @highest_exponent < 1
@sprintf = ['%ix^%i'] + ['%+ix^%i']*(coefficients.size-2) << '%+i'
end
def to_s
@coefficients.to_enum(:each_with_index).inject([]) {|builder, (coefficient, index)|
builder.push coefficient == 0 ?
View polynomial.rb
class Polynomial
def initialize(arg)
raise ArgumentError.new('We expect an array at least') unless arg.is_a? Array
raise ArgumentError.new('Need at least 2 coefficients') if arg.length < 2
@exponents = []
arg.reverse.inject(0) do |index,item|
@exponents.push( { "factor" => item, "exponent" => index }) unless item == 0
index + 1
end
You can’t perform that action at this time.