-
PolynomialRootmyCode/ShortestCodeChallenge 2016. 4. 6. 20:25
https://codefights.com/challenge/weNspy2jEkhc6aBq9
You are given a list of coefficients of a polynomial and its possible root. The length of the list is equal to the degree of the polynomial - 1, and the constant term of the polynomial is the last element of the list (i.e.
polynomial[len(polynomial) - 1]
).Find out if the given number is a root of the polynomial.
Example
For
polynomial = [1,-20,150,-500,625]
andpossibleRoot = 5
, the output should bePolynomialRoot(polynomial, possibleRoot) = true
.The polynomial equals
x4 - 20 * x3 + 150 * x2 - 500 * x + 625
, and forx = 5
it equals0
.첫번째로 성공한 ShortestCodeChallenge
주어진 배열에 해당하는 방정식에 주어진 근이 방정식의 근인지 아닌지를 판별하는 함수를 만들어야한다.
내 코드
x의 값에 원하는 근을 넣어서 직접 확인해보는 알고리즘이다.
마치 중3이 방정식을 푸는 듯이, 그 흐름을 그대로 따라가면서 작성했다.
1등의 코드..
이게 뭐지..
'myCode > ShortestCodeChallenge' 카테고리의 다른 글
DigitBuilder [Subset sum problem] (0) 2016.04.25 Last Two [Fast Exponentiation Algorithm] (0) 2016.04.21 ChessBoardShapes [Flood Fill Algorithm] (0) 2016.04.21 Compress (0) 2016.04.13 The Euler's totient (0) 2016.04.07