ComeçarComece de graça

Write a function to check factorability

Let us write a function to evaluate whether any given quadratic is factorable or not. The arguments to the function will be the coefficient values a b and c for a given quadratic of the form $$ ax^2 + bx + c $$

and we will determine whether the discriminant of the quadratic formula $$ b^2 - 4ac $$

is a perfect square. If it is, then the quadratic is factorable.

Este exercício faz parte do curso

Probability Puzzles in R

Ver curso

Instruções do exercício

  • Fill in the condition to check whether the solutions to the quadratic equation are imaginary.
  • Write the conditional statement to specify that the next section should run only when the previous condition is FALSE.
  • Return the result of the check for whether the discriminant is a perfect square, thus making the quadratic factorable.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

is_factorable <- function(a,b,c){
  # Check whether solutions are imaginary
  if(b^2 - 4*a*c ___){
    return(FALSE)
  # Designate when the next section should run
  } ___ {
    sqrt_discriminant <- sqrt(b^2 - 4*a*c) 
    # return TRUE if quadratic is factorable
    return(___)    
  }
}
Editar e executar o código