Skip to main content
edited tags
Link
alephalpha
  • 50k
  • 7
  • 68
  • 182
Commonmark migration
Source Link

Given a polynomial, determine whether it's prime.

A polynomial is ax^n + bx^(n-1) + ... + dx^3 + ex^2 + fx + g, where each term is a constant number (the coefficient) multiplied by a nonnegative integer power of x. The highest power with a nonzero coefficient is called the degree. For this challenge, we only consider polynomials of at least degree 1. That is, each polynomial contains some x. Also, we only use polynomials with integer coefficients.

Polynomials can be multiplied. For example, (x+3)(2x^2-2x+3) equals 2x^3+4x^2-3x+9. Thus, 2x^3+4x^2-3x+9 can be factored into x+3 and 2x^2-2x+3, so it is composite.

Other polynomials can not be factored. For example, 2x^2-2x+3 is not the product of any two polynomials (ignoring constant polynomials or those with non-integer coefficients). Hence, it is prime (also known as irreducible).

##Rules

Rules

  • Input and output can be through any standard way.
  • Input can be a string like 2x^2-2x+3, a list of coeffecients like {2,-2,3}, or any similar means.
  • Output is either a truthy value if it's prime, or a falsey value if it's composite. You must yield the same truthy value for all primes, and the same falsey value for all composite polynomials.
  • The input will be of at least degree 1 and at most degree 10.
  • You may not use built-in tools for factorization (of integers or expressions) or equation solving.

##Examples

Examples

###True - prime x+3 -2x x^2+x+1 x^3-3x-1 -2x^6-3x^4+2 3x^9-8x^8-3x^7+2x^3-10

True - prime

###False - composite x^2 x^2+2x+1 x^4+2x^3+3x^2+2x+1 -3x^7+5x^6-2x x^9-8x^8+7x^7+19x^6-10x^5-35x^4-14x^3+36x^2+16x-12

x+3
-2x
x^2+x+1
x^3-3x-1
-2x^6-3x^4+2
3x^9-8x^8-3x^7+2x^3-10

False - composite

x^2
x^2+2x+1
x^4+2x^3+3x^2+2x+1
-3x^7+5x^6-2x
x^9-8x^8+7x^7+19x^6-10x^5-35x^4-14x^3+36x^2+16x-12

Given a polynomial, determine whether it's prime.

A polynomial is ax^n + bx^(n-1) + ... + dx^3 + ex^2 + fx + g, where each term is a constant number (the coefficient) multiplied by a nonnegative integer power of x. The highest power with a nonzero coefficient is called the degree. For this challenge, we only consider polynomials of at least degree 1. That is, each polynomial contains some x. Also, we only use polynomials with integer coefficients.

Polynomials can be multiplied. For example, (x+3)(2x^2-2x+3) equals 2x^3+4x^2-3x+9. Thus, 2x^3+4x^2-3x+9 can be factored into x+3 and 2x^2-2x+3, so it is composite.

Other polynomials can not be factored. For example, 2x^2-2x+3 is not the product of any two polynomials (ignoring constant polynomials or those with non-integer coefficients). Hence, it is prime (also known as irreducible).

##Rules

  • Input and output can be through any standard way.
  • Input can be a string like 2x^2-2x+3, a list of coeffecients like {2,-2,3}, or any similar means.
  • Output is either a truthy value if it's prime, or a falsey value if it's composite. You must yield the same truthy value for all primes, and the same falsey value for all composite polynomials.
  • The input will be of at least degree 1 and at most degree 10.
  • You may not use built-in tools for factorization (of integers or expressions) or equation solving.

##Examples

###True - prime x+3 -2x x^2+x+1 x^3-3x-1 -2x^6-3x^4+2 3x^9-8x^8-3x^7+2x^3-10

###False - composite x^2 x^2+2x+1 x^4+2x^3+3x^2+2x+1 -3x^7+5x^6-2x x^9-8x^8+7x^7+19x^6-10x^5-35x^4-14x^3+36x^2+16x-12

Given a polynomial, determine whether it's prime.

A polynomial is ax^n + bx^(n-1) + ... + dx^3 + ex^2 + fx + g, where each term is a constant number (the coefficient) multiplied by a nonnegative integer power of x. The highest power with a nonzero coefficient is called the degree. For this challenge, we only consider polynomials of at least degree 1. That is, each polynomial contains some x. Also, we only use polynomials with integer coefficients.

Polynomials can be multiplied. For example, (x+3)(2x^2-2x+3) equals 2x^3+4x^2-3x+9. Thus, 2x^3+4x^2-3x+9 can be factored into x+3 and 2x^2-2x+3, so it is composite.

Other polynomials can not be factored. For example, 2x^2-2x+3 is not the product of any two polynomials (ignoring constant polynomials or those with non-integer coefficients). Hence, it is prime (also known as irreducible).

Rules

  • Input and output can be through any standard way.
  • Input can be a string like 2x^2-2x+3, a list of coeffecients like {2,-2,3}, or any similar means.
  • Output is either a truthy value if it's prime, or a falsey value if it's composite. You must yield the same truthy value for all primes, and the same falsey value for all composite polynomials.
  • The input will be of at least degree 1 and at most degree 10.
  • You may not use built-in tools for factorization (of integers or expressions) or equation solving.

Examples

True - prime

x+3
-2x
x^2+x+1
x^3-3x-1
-2x^6-3x^4+2
3x^9-8x^8-3x^7+2x^3-10

False - composite

x^2
x^2+2x+1
x^4+2x^3+3x^2+2x+1
-3x^7+5x^6-2x
x^9-8x^8+7x^7+19x^6-10x^5-35x^4-14x^3+36x^2+16x-12
Notice removed Reward existing answer by Justin
Bounty Ended with njpipeorgan's answer chosen by Justin
Notice added Reward existing answer by Justin
Bounty Started worth 500 reputation by Justin
added 17 characters in body
Source Link
Ypnypn
  • 10.9k
  • 2
  • 31
  • 80

Given a polynomial, determine whether it's prime.

A polynomial is ax^n + bx^(n-1) + ... + dx^3 + ex^2 + fx + g, where each term is a constant number (the coefficient) multiplied by a nonnegative integer power of x. The highest power with a nonzero coefficient is called the degree. For this challenge, we only consider polynomials of at least degree 1. That is, each polynomial contains some x. Also, we only use polynomials with integer coefficients.

Polynomials can be multiplied. For example, (x+3)(2x^2-2x+3) equals 2x^3+4x^2-3x+9. Thus, 2x^3+4x^2-3x+9 can be factored into x+3 and 2x^2-2x+3, so it is composite.

Other polynomials can not be factored. For example, 2x^2-2x+3 is not the product of any two polynomials (ignoring constant polynomials or those with non-integer coefficients). Hence, it is prime (also known as irreducible).

##Rules

  • Input and output can be through any standard way.
  • Input can be a string like 2x^2-2x+3, a list of coeffecients like {2,-2,3}, or any similar means.
  • Output is either a truthy value if it's prime, or a falsey value if it's composite. You must yield the same truthy value for all primes, and the same falsey value for all composite polynomials.
  • The input will be of at least degree 1 and at most degree 10.
  • You may not use built-in tools for factorization (of integers or expressions) or equation solving.

##Examples

###True - prime x+3 -2x x^2+x+1 x^3-3x-1 -2x^6-3x^4+2 3x^9-8x^8-3x^7+2x^3-10

###False - composite x^2 x^2+2x+1 x^4+2x^3+3x^2+2x+1 -3x^7+5x^6-2x x^9-8x^8+7x^7+19x^6-10x^5-35x^4-14x^3+36x^2+16x-12

Given a polynomial, determine whether it's prime.

A polynomial is ax^n + bx^(n-1) + ... + dx^3 + ex^2 + fx + g, where each term is a constant number (the coefficient) multiplied by a nonnegative integer power of x. The highest power with a nonzero coefficient is called the degree. For this challenge, we only consider polynomials of at least degree 1. That is, each polynomial contains some x. Also, we only use polynomials with integer coefficients.

Polynomials can be multiplied. For example, (x+3)(2x^2-2x+3) equals 2x^3+4x^2-3x+9. Thus, 2x^3+4x^2-3x+9 can be factored into x+3 and 2x^2-2x+3, so it is composite.

Other polynomials can not be factored. For example, 2x^2-2x+3 is not the product of any two polynomials (ignoring constant polynomials or those with non-integer coefficients). Hence, it is prime.

##Rules

  • Input and output can be through any standard way.
  • Input can be a string like 2x^2-2x+3, a list of coeffecients like {2,-2,3}, or any similar means.
  • Output is either a truthy value if it's prime, or a falsey value if it's composite. You must yield the same truthy value for all primes, and the same falsey value for all composite polynomials.
  • The input will be of at least degree 1 and at most degree 10.
  • You may not use built-in tools for factorization (of integers or expressions) or equation solving.

##Examples

###True - prime x+3 -2x x^2+x+1 x^3-3x-1 -2x^6-3x^4+2 3x^9-8x^8-3x^7+2x^3-10

###False - composite x^2 x^2+2x+1 x^4+2x^3+3x^2+2x+1 -3x^7+5x^6-2x x^9-8x^8+7x^7+19x^6-10x^5-35x^4-14x^3+36x^2+16x-12

Given a polynomial, determine whether it's prime.

A polynomial is ax^n + bx^(n-1) + ... + dx^3 + ex^2 + fx + g, where each term is a constant number (the coefficient) multiplied by a nonnegative integer power of x. The highest power with a nonzero coefficient is called the degree. For this challenge, we only consider polynomials of at least degree 1. That is, each polynomial contains some x. Also, we only use polynomials with integer coefficients.

Polynomials can be multiplied. For example, (x+3)(2x^2-2x+3) equals 2x^3+4x^2-3x+9. Thus, 2x^3+4x^2-3x+9 can be factored into x+3 and 2x^2-2x+3, so it is composite.

Other polynomials can not be factored. For example, 2x^2-2x+3 is not the product of any two polynomials (ignoring constant polynomials or those with non-integer coefficients). Hence, it is prime (also known as irreducible).

##Rules

  • Input and output can be through any standard way.
  • Input can be a string like 2x^2-2x+3, a list of coeffecients like {2,-2,3}, or any similar means.
  • Output is either a truthy value if it's prime, or a falsey value if it's composite. You must yield the same truthy value for all primes, and the same falsey value for all composite polynomials.
  • The input will be of at least degree 1 and at most degree 10.
  • You may not use built-in tools for factorization (of integers or expressions) or equation solving.

##Examples

###True - prime x+3 -2x x^2+x+1 x^3-3x-1 -2x^6-3x^4+2 3x^9-8x^8-3x^7+2x^3-10

###False - composite x^2 x^2+2x+1 x^4+2x^3+3x^2+2x+1 -3x^7+5x^6-2x x^9-8x^8+7x^7+19x^6-10x^5-35x^4-14x^3+36x^2+16x-12

Tweeted twitter.com/#!/StackCodeGolf/status/578989736238383104
Post Undeleted by Ypnypn
Post Deleted by Ypnypn
Source Link
Ypnypn
  • 10.9k
  • 2
  • 31
  • 80
Loading