Skip to content

Commit

Permalink
Make degree get-only
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamWhiteHat committed Dec 30, 2021
1 parent 6a74a00 commit 708df36
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions Polynomial/Polynomial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,20 @@ public partial class Polynomial : ICloneable<Polynomial>, IComparable, IComparab
/// <summary>
/// Gets the degree of the polynomial.
/// </summary>
public int Degree { get; private set; }
public int Degree
{
get
{
if (_terms.Any())
{
return _terms.Max(term => term.Exponent);
}
else
{
return 0;
}
}
}

/// <summary>
/// Gets or sets the Coefficient of the term of the specified degree.
Expand Down Expand Up @@ -109,7 +122,6 @@ public Polynomial(BigInteger n, BigInteger polynomialBase)

public Polynomial(BigInteger n, BigInteger polynomialBase, int forceDegree)
{
Degree = forceDegree;
SetTerms(GetPolynomialTerms(n, polynomialBase, Degree));
}

Expand All @@ -126,19 +138,6 @@ private void RemoveZeros()
{
_terms = Term.GetTerms(new BigInteger[] { 0 }).ToList();
}
SetDegree();
}

private void SetDegree()
{
if (_terms.Any())
{
Degree = _terms.Max(term => term.Exponent);
}
else
{
Degree = 0;
}
}

private static List<Term> GetPolynomialTerms(BigInteger value, BigInteger polynomialBase, int degree)
Expand Down

0 comments on commit 708df36

Please sign in to comment.