5 kyu
Constructing polynomials
56 of 73FArekkusu
Loading description...
Mathematics
Performance
Fundamentals
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Solved this Kata in Python. Firstly wrote code in JS then translated it into Python. In JS it passed test cases for 1 - 10 roots, but failed for some '625-675 roots' cases. And it is impossible to debug it uses error message: expected 'x^673 - 2153x^672 + 1140664x^671 + 86…' to equal 'x^673 - 2153x^672 + 1140664x^671 + 86…' because in this message we can't undestand what is going wrong!!! More over the same Code translated to Python passed all tests! It is needed to do something with it!
that's because
chai.config.truncateThreshold = 0;
should be added to the JavaScript tests suite. (also,strictEqual
should be used instead ofequal
)Thanks for answer
This 5kyu kata is much more difficult than similar 4kyu("Simplifying multilinear polynomials" and "Differentiate a polynomial"). Its level needs to be raised to 3 kyu, then it will be solved and it will not gather dust at the bottom
I think some would disagree: https://www.codewars.com/api/v1/code-challenges/5b2d5be2dddf0be5b00000c4/assessed-ranks
Probably this is some very old voting, or it was voted by those who decide only high-level kata and from this everything seems easier to them. The two 4kyu kata that I gave above are very similar in type of task, but much easier and in terms of the number of transformations and do not require optimization, but this one does.
https://www.codewars.com/kata/540d0fdd3b6532e5c3000b5b
Here I met 95% the same kata and it is 3kyu and a drum roll... its difficulty is also lower than this 5kyu kata
hello creator, cannot access the sympy module. Is it not allowed to be used? If it is, may you please make it accessible? Thank you.
2nd question: only real input numbers to be considered, no imaginary numbers, correct? cheers
This comment has been hidden.
According to CW wiki Sympy is not available.
good to know, thanks
excellent kata
I think the term 'quotient' in the description should be changd to 'coefficient'.
JavaScript, random tests exceed
Number.MAX_SAFE_INTEGER
Yeah, forgot JS can't handle such insanely big numbers, removed it altogether (at least for now~~ it won't be coming back as partially implementing bigInt is not in the scope of the problem, sorry for the inconvenience).~~Figured out that there is a BigNumber library available on CW and returned the JS version. Hope it'll be working okay ¯\_(ツ)_/¯
This comment has been hidden.
Replaced assertions, should be okay now.
Changed the test suite to be less severe. Both your solutions pass the test suite now, but considering how python is very stupid and saving stuff into variables may give a considerable speed-up (for example: your faster code - 5 sec, your slower code - 6 sec, 16% less time for the newest test suite) I'm not sure if it's really a micro-optimization or an actually better approach.
EDIT: just checked my statement to not sound stupid (approximate values):
Ok, sounds good again. ;)
One more quick issue: you need to define clearly that the coefficient for the highest degree term must always be 1; there are actually an infinite number of polynomials for any set of given roots without this restriction.
Added to the description.
This comment has been hidden.
It was supposed to ban the worst possible algos like the thing I first came up with (1.5 sec for 1 test with 20 roots -_-). Removed
performance
tag for now. Will see if I can speed up my code.By the way I checked my code on 2 Python version. Surprisingly it times out in 2.7 but passes after 10.5 sec in 3.6.
Performance requirement is back! 10000 tests with number of roots going up to 100. Your solution almost passes it now :)
Turns out my new solution is the same as ZED's one, which is why only his solution survived :D
one problem, though:
currently, your tests about the simplifications of the expression are almost only fixed tests because the random ranges you use have very little chances to generate the 0 coef for the degree 0 of the polynome. For instance, I passed several times the full batch of random tests while failing 4 fixed tests. So you have to update your random tests to be sure that several tests about each edge case will show up.
EDIT: why a "performances" tag?? I don't see the point for this kind of task... :o
What exactly do you mean by simplification?
There's a low chance that the tests produce polynomials that need to be reduced from, say, "x^3 + 5x^2 + 0x + 8" down to "x^3 + 5x^2 + 8".
yes, that's it.
Added randomizer for such cases.
EDIT: improved randomizer to be more random.
Really cool one! Funny tests comments! But really too long test suite!!! ("Seriously", yeah!!?). No seriously, that makes chock my browser. It least, silence the assertions when they are succesful, so that you do not have so much display in the console. And that may make the test suite a bit faster too (currently 9s...)
Lowered amount of tests to 500 per N of roots.