4 kyu
Simplifying multilinear polynomials
2,812 of 4,907SleepingCode
Loading description...
Mathematics
Strings
Regular Expressions
Parsing
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.
Hi! An error is issued: poly = 3a+b+4ac+bc-ab+3a-cb-a-a Sorry :( : 'b+4a-ab+4ac' should equal '4a+b-ab+4ac' by the condition of the problem, this is true! 'b+4a-ab+4ac'
poly = -8fk+5kv-4yk+7kf-qk+yqv-3vqy+4ky+4kf+yvqkf Sorry :( : '-kq+3fk+5kv-2qvy+fkqvy' should equal '3fk-kq+5kv-2qvy+fkqvy' by the condition of the problem, this is true! '-kq+3fk+5kv-2qvy+fkqvy'
Fix it or test it or tell me where I'm wrong.
You haven't implemented this case:
In the first example,
4a
should come first beforeb
sincea
<b
in lexicographical order. Same with the second example,fk
<kq
.Solved the problem. The question arose due to a misunderstanding. Clear question == clear answer.
On Haskell there is a bug in testing code:
In random tests, for example, having a list of monomials: ("", -1), ("b", -9), <...> so, the system says: expected: "--9b+ <...>" got: "-9b <...>"
Obviously, that testing code doesn't work correct for monomial "-1", because, it reduces that to "-" (like "-1a" should be reduced to "-a")
So, could you please, check this behaviour and fix it?
Regards
duplicate of this issue
Python fork (author gone)
Test Passed Test Passed '5ab-c' should equal '-c+5ab' Test monomial length ordering '-abc+3a+2ac' should equal '3a+2ac-abc' 'xyz-xz' should equal '-xz+xyz' Test lexicographic ordering 'a+ac-ab' should equal 'a-ab+ac' 'xyz+byz' should equal 'byz+xyz' Test no leading + '-y+x' should equal 'x-y' 'y-x' should equal '-x+y'
As for me I solved it.
UPD
But Anyways I've come up with it. Just added sorting in some places)))
Thank you for this kata! Nice! I've been solving for a long time, but i enjoyed it.
How do I understand which tests were used in the section "More complicated tests"? Otherwise I won't understand how to fix the code. All other tests are solved correctly.
One of the test cases is looking for -c+5ab but the instructions say:
All monomials appears in order of increasing number of variables, e.g.: "-abc+3a+2ac" -> "3a+2ac-abc", "xyz-xz" -> "-xz+xyz"
doesn't "5ab" have a number of variables greater than "-c"? Maybe you're misunderstanding the instructions. Each letter is a variable, you must sort by the "number of variables", not by the coefficient
Great kata! Loved it
D translation
Approved :)
I've tried my code in Anaconda, working perfect. When I run the tests here, some messages appear saying it is not correctly ordered or whatever.. anybody know what could be going on?
Your code not working is not an issue. See there: https://docs.codewars.com/training/troubleshooting/
I've passed all the test and most of the attempts but i keep getting an error with the random tests
python fork with new test framework:
https://www.codewars.com/kumite/62c4f04166faa1000e1ccf7f?sel=62c4f04166faa1000e1ccf7f
Rejected, no random tests
This comment has been hidden.
Rust translation (author is inactive).
Log 32a+b-ab+4ac Sorry :( : '32a+b-ab+4ac' should equal '4a+b-ab+4ac'
That means you should have returned '4a+b-ab+4ac', and you have not, and it is not a kata issue. Please read the documentation (see left panel) before raising issues like this.
saw an error, sorry
quite a challenge, but an enjoyed after passed
my solution might be too long but i passed at least
This kata was awesome
In Haskell the test logs should provide the input, at least in case of fails.
Random tests in Haskell sometimes generate cases with constants:
[("abcy",-14),("",-8),("axyz",-9),("bcdz",-3)]
,or with coefficients equal to zero:
[("abz",15),("abcx",10),("adx",-6),("abcdxyz",9),("axz",0),("abc",3)]
.It makes the task more fun, but it contradicts the rules laid down in the description:
I'd suggest either changing the description or fixing random tests.
Tests should be changed in Haskell, because it appears to be the only language doing this.
Ruby 3.0 should be enabled.
Enabled in this fork
Help me, please. My code return: Sorry :( : '4a-2a+b-ab+4ac' should equal '4a+b-ab+4ac' But why? 4a-2a = 2a, not 4a...
Print the input
This comment has been hidden.
fork
Haskell GHC 8.2
Случайный тест задания генерирует ошибочные строки - генерирует вместе знаки '-' и '+', видимо пропускает ("",1)
1,
[("cy",3),("adxyz",12),("abcxy",4),("abx",11),("abdxy",-5),("acy",1),("abcd",4),("abdx",11),("bxy",-10),("cdxyz",4),("bcdxyz",5),("bcyz",-1),("bdxy",1),("",1),("x",-4),("abcy",-10),("cd",-9),("bdxy",15),("z",-8),("abcy",-10),("bxz",-4),("xy",-2),("xz",-8),("abcdxyz",-10),("adxyz",-10),("abdxz",11),("bcdyz",-5),("bdxy",3),("bcdz",-12),("acy",-9),("acy",-13),("bcz",2),("abcdx",-6),("adxy",-10),("bcdx",0),("xyz",-13),("acxy",12),("bcd",-2),("z",-15),("acdyz",-6)]
ожидает получить результат
"-c+13x+12z+10by-6dz+9xz-7abx-acz-7bcz-25bdy+15cyz+2abcd-2abdx-13abyz-bcdx-cxyz+2dxyz+8abcdz+abcxz+13abdxy-9abdxz-6bcxyz-13abcdxy"
2,
[("acz",-1),("abcdxy",-13),("abdxy",13),("abx",-7),("",1),("abdxz",-9),("bcz",-6),("abcxz",1),("bdy",-13),("c",-1),("x",13),("abcd",2),("dz",-6),("z",12),("bcz",-1),("abdx",-2),("bcdx",-1),("abyz",-13),("bdy",-12),("abcdz",8),("cxyz",-1),("dxyz",2),("by",10),("bcxyz",-6),("xz",9),("cyz",15)]
генерирует
"-acz-13abcdxy+13abdxy-7abx+-9abdxz-6bcz+abcxz-13bdy-c+13x+2abcd-6dz+12z-bcz-2abdx-bcdx-13abyz-12bdy+8abcdz-cxyz+2dxyz+10by-6bcxyz+9xz+15cyz"
ожидает получить результат
"-c+13x+12z+10by-6dz+9xz-7abx-acz-7bcz-25bdy+15cyz+2abcd-2abdx-13abyz-bcdx-cxyz+2dxyz+8abcdz+abcxz+13abdxy-9abdxz-6bcxyz-13abcdxy"
3,
[("y",-9),("bcdxz",14),("acd",-10),("bx",-13),("by",10),("bx",-8),("abcdy",-8),("x",15),("ayz",4),("axz",-14),("abcyz",-2),("abcxz",-15),("acyz",-7),("abz",-9),("by",-14),("abdxz",11),("cdy",1),("abcy",2),("dx",-15),("bz",-13),("xyz",7),("cz",2),("abcd",-11),("acxz",9),("abx",7),("acyz",-13),("bz",8),("acdxyz",-14),("abcyz",-4),("acz",14),("ay",-10),("ab",-9),("acdxy",-11),("abdx",11),("abz",9),("cxz",-10),("abxz",12),("adxyz",7),("cdxz",-13),("bxz",-5),("cyz",8),("acdxy",-15),("bcdyz",4),("acdy",-8),("bcyz",-13),("",1),("abcd",4),("abdxz",-3),("acdxz",10)]
генерирует
"-9y+14bcdxz-10acd-13bx+10by-8bx-8abcdy+15x+4ayz-14axz-2abcyz-15abcxz-7acyz-9abz-14by+11abdxz+cdy+2abcy-15dx-13bz+7xyz+2cz-11abcd+9acxz+7abx-13acyz+8bz-14acdxyz-4abcyz+14acz-10ay-9ab-11acdxy+11abdx+9abz-10cxz+12abxz+7adxyz-13cdxz-5bxz+8cyz-15acdxy+4bcdyz-8acdy-13bcyz++4abcd-3abdxz+10acdxz"
ожидает получить результат
"15x-9y-9ab-10ay-21bx-4by-5bz+2cz-15dx+7abx-10acd+14acz-14axz+4ayz-5bxz+cdy-10cxz+8cyz+7xyz-7abcd+2abcy+11abdx+12abxz-8acdy+9acxz-20acyz-13bcyz-13cdxz-8abcdy-15abcxz-6abcyz+8abdxz-26acdxy+10acdxz+7adxyz+14bcdxz+4bcdyz-14acdxyz"
4,
[("az",8),("abxz",-13),("a",2),("abx",8),("abcdxyz",-5),("cz",10),("bcdxy",-6),("axz",1),("z",-6),("acz",-10),("abdy",-10),("",1),("ayz",8),("xz",-2),("bcd",3),("bcd",9),("abxyz",-8),("abxy",-4),("abx",-14),("bcdz",-14),("cdxy",-5),("",-5),("adz",-5),("bdy",-5),("d",-9),("adxz",5),("abxz",1),("abcdyz",10),("dy",-10),("bcdxy",14),("ay",14),("abcxy",-5),("acdy",-15),("ax",-6),("bdxyz",-9)]
генерирует
"+8az-13abxz+2a+8abx-5abcdxyz+10cz-6bcdxy+axz-6z-10acz-10abdy++8ayz-2xz+3bcd+9bcd-8abxyz-4abxy-14abx-14bcdz-5cdxy-5-5adz-5bdy-9d+5adxz+abxz+10abcdyz-10dy+14bcdxy+14ay-5abcxy-15acdy-6ax-9bdxyz"
ожидает получить результат
"-4+2a-9d-6z-6ax+14ay+8az+10cz-10dy-2xz-6abx-10acz-5adz+axz+8ayz+12bcd-5bdy-10abdy-4abxy-12abxz-15acdy+5adxz-14bcdz-5cdxy-5abcxy-8abxyz+8bcdxy-9bdxyz+10abcdyz-5abcdxyz"
5,
[("a",-15),("bxyz",-5),("bc",3),("",-1),("bcz",2),("bcxy",-6),("by",-15),("b",9),("bcdyz",-15),("bcdxz",-11),("abcdxyz",6),("bcdxz",-5),("ax",-1),("dxyz",-3),("abcyz",1),("ay",-13),("a",2),("abdxyz",4),("cdxyz",4),("abcxz",-12),("cd",-8),("abcdxyz",7),("axyz",-11),("xyz",-5),("bcxy",-10),("yz",7),("adyz",-2),("abyz",10),("bdz",-10),("cdyz",-12),("cdz",-11),("adxz",-5),("abcdx",8),("cx",-13),("bcxyz",2),("acdx",-11),("abcyz",4),("dxyz",11),("acx",-6),("y",-11),("abdxyz",0),("bz",2),("bcy",-12),("adz",-15),("x",3),("bcx",-6),("dxyz",-14),("cdy",5),("abxy",-9),("bcdz",-9),("cdx",-1),("b",14),("acxz",10),("abcdxz",-1),("cd",-3),("bxy",8),("xyz",-15),("xyz",-4)]
генерирует
"-15a-5bxyz+3bc-+2bcz-6bcxy-15by+9b-15bcdyz-11bcdxz+6abcdxyz-5bcdxz-ax-3dxyz+abcyz-13ay+2a+4abdxyz+4cdxyz-12abcxz-8cd+7abcdxyz-11axyz-5xyz-10bcxy+7yz-2adyz+10abyz-10bdz-12cdyz-11cdz-5adxz+8abcdx-13cx+2bcxyz-11acdx+4abcyz+11dxyz-6acx-11y-0abdxyz+2bz-12bcy-15adz+3x-6bcx-14dxyz+5cdy-9abxy-9bcdz-cdx+14b+10acxz-abcdxz-3cd+8bxy-15xyz-4xyz"
ожидает получить результат
"--13a+23b+3x-11y-ax-13ay+3bc-15by+2bz-11cd-13cx+7yz-6acx-15adz-6bcx-12bcy+2bcz-10bdz+8bxy-cdx+5cdy-11cdz-24xyz-9abxy+10abyz-11acdx+10acxz-5adxz-2adyz-11axyz-9bcdz-16bcxy-5bxyz-12cdyz-6dxyz+8abcdx-12abcxz+5abcyz-16bcdxz-15bcdyz+2bcxyz+4cdxyz-abcdxz+4abdxyz+13abcdxyz"
6,
[("yz",9),("",-1)]
возможно генерирует правильно
ожидает
"-+9yz"
You should describe your issue in English and it looks like it's a duplicate as pointed out above or below
One of the python test cases starts with a +, which seems to go against the rules that any leading + on a polynomial will be hidden.
This test is in JS too.
The random tests in Haskell sometimes contain the substring "--"
Duplicate issue below
One of the python tests is not correct.
Sorry :( : '6a+b-ab+4ac+bc-aabc' should equal '4a+b-ab+4ac'
a * a * b * c = a^2 * b * c. To get 4a+b-ab+4ac' the test should be '6a+b–ab+4ac+bc-2a-bc'
This comment has been hidden.
I was thinking about this. When I put in the polynomial into my solution using a Python debugger, I got the correct answer. So, I am not sure either. I was using Pandas which is something I don't see used in many solutions. Perhaps it has something to do with the character encoding.
This comment has been hidden.
Im trying to write the complete regex expression but simply it doesnt recognise
Here is the real expression:
https://paste.ofcode.org/JC3hMbJQ2JduhbEPsfVatp
My first reaction was to suggest to enable Haskell 8.2.2 because 7.10.3 doesn't have regex modules available, but that forced me to get my hands dirty with some Parsec and it was a good fun :)
Test.assertEquals(simplify("dc+dcba"), "cd+abcd")
I keep getting
Expected: 'cd+abcd', instead got: 'abcd+cd'
, what am I missing?@justbrody: post as a
Question
, not as anIssue
@FArekkusu, thanks. @Blind4Basics, I will
This comment has been hidden.
Not an issue of the kata, you solved it nevertheless
Still incorrect expected output for randomised test in JS version of kata sometimes when we have 0 koef in input.
For example,
Hi, I see that people are complaining about Haskell tests. But they don't seem to say if this bugs are restraining them from passing the kata (or are those bugs only hapening sometimes) As I have problems too... So, I'd like to know if anyone has passed this kata in Haskell ?
You could click Details and check how many completions there are for Haskell:
There are issue reports as old as 1 year for Haskell, maybe someone could fix them.
Hi everyone, I'm the author of the original version of the kata (python). I'm sorry to known that there are issues with the random tests for the other languages... apparently, codewars don't warn the authors of other versions...
Expected: '4a+b-ab+4ac' How is that b comes before ab in lexicografical order?
Rule 2: All monomials appears in order of increasing number of variables
Rule 3: If two monomials have the same number of variables, they appears in lexicographic order
Yes, i realized just after i posted it and wanted to delete my own question but i couldn't find it. Sorry for not reading the instructions 😅
Bugs in random tests for Haskell: sometimes expected value starts with "--.....", which is clearly wrong.
Example:
-
stands for zero degree monomial-1
.duplicate of this issue
It is frustrated sometimes when all the test are passed except the random test without the specific test input. Why not giving the specific case, not just Expected, Anctual and something like [("abcdxyz",0),("c",8),("bd",14)...] that helps little to find the bug in my code.
why not just print the input in the console yourself?
Yeah, I just find a way to print the input, but this kata still has some bugs about the input, such as "-1" -> "-" case, and the invalid test case like "-5xy+-6d". Anyway, after modifying according to the input bugs, random tests are passed by chance.
Haskell version: I only see expected and actual. How do I see what the input is which is generating this simplified expression?
In Javascript, all the standard tests pass, but all the random tests give me an error along the lines of:
Expected: '-4b+11bx-19bxz', instead got: '-4b+11bx-19bxz+function (){\n var i=this.length,j,k;\n for (;i;){\n j=Math.floor(Math.random()*this.length);\n k=this[--i];this[i]=this[j];this[j]=k;\n }\n return this;\n}shuffle'
When I replicate these random tests in something like codepen.io, I get the correct answer every time.
Hi I fail one of the tests with this message: Sorry :( : '-3n+10hn-6hjn-8hjnt' should equal '-2n+2hjn+hjnt'
Doesn't make much sense to me. Can you help?
Chris
Can you post some code up ? That would be helpful
the same problem. All the tests are correct except this one. I get messege: Sorry :( : '-2n+2hjn+7hjnt-6hjnt' should equal '-2n+2hjn+hjnt' But in PyCharm I get exactly same result as it should be. Does anybody know the solution?
Looks way simpler than it really is. Really enjoyed this one despite being stuck for over an hour as a result of speeding through the details.
When do you manage to complete kata in less than an hour?
I must be terrible... or overambitious with my choices xD.
Test don't apply the next rules:
ty
PHP random tests seem to be off as well.
For: -12dy+9yzd-9dyz-13y+8y-1-11yd+15yd+9y it expects: 4y-8dy-10dyz
The "1" term should not be there according to the description and the test result makes no sense as a result.
Still some bugs in the random tests of the Haskell version.
eg 1) expected: "-+14c+11x... due to a ("",-1) term
eg 2) expected: "z-6ab-9ac... but there was an (uncancelled) ("",1) term present.
Happily, random test cases are random, so two presses later I had clean green.
Very good little kata ty very much :D
In JavaScript all the Random test gives me the next error:
```TypeError: Cannot read property 'toString' of undefined at simplify at Test.it._ at begin at Object.it at Test.describe._ at /runner/frameworks/javascript/cw-2.js:159:11 at Promise._execute at Promise._resolveFromExecutor at new Promise at Object.describe
at Object.handleError
at ContextifyScript.Script.runInThisContextat Object.exports.runInThisContext
The regular tests work fine and tyring one of the random the algorithm also work... So it must be something about the random tests generator.
Quite possibly a solution problem, not a kata problem. 441 Submitted solutions did not have this problem.
You didn't, explicitly or implicitly, call
.toString()
on anundefined
value somewhere in your solution, did you?Closing.
Ruby: Random Tests return incorrect expected values:
one example: Testing for +7dy+12d-14d ✘ It should work for random inputs too - Expected: "26d+7dy", instead got: "-2d+7dy"
This is because your code is mutating the input.
Fixed in this fork
Haskell: I still get something like "-+4ab" in random tests. I would suggest to give up random tests. If you want to prepare unit test with really hardcore case you should invent it and hardcode. Writing tests that compare result with implementation written by someone else is a very bad approach. You should compare the result to well known and manually validated value.
Duplicate issue above
Haskell
I enjoyed this kata. Thank you.
Regarding Haskell tests, your
showMember
function returns wrong result on constant values ("", 1) and ("", -1). Namely, yourshowMember ("", 1)
returns"+"
but it should be"+1"
.In a full example, let
xs = [("x", 1), ("", 1)]
, then your code givessimplify' xs == "x"
Duplicate issue above
I don't understand why the result should be 'x-y'
In the description, it says that there is no restriction for '-' sign.
The error I'm facing is: '-y+x' should equal 'x-y'
This comment has been hidden.
I need a bit of help!
With the random input "-3cyd+14cdy+8d+2d-11cyd-6yd-5d-4d" I get the message "It should work for random inputs too - Expected: "d-6dy+6cdy", instead got: "d-6dy"" Its a bug in the random imput generation?
When the random input start whit "-" is ignored! Input: "-11zb-13zb" Output: "It should work for random inputs too - Expected: "-2bz", instead got: "-24bz""
Duplicate issue
Yep, that 'PolynomialSimplifier' class was a rude one. If the description says "write a function", I do not necessarily imply to "write a method". Description could have been cleaner; I could have produced a non-fake OO solution.
Hi terminus_technicus,
the problem with the given class should be resolved. It is not necessary to write a class to solve this kata, so the description is correct as it is. The purpose of the given class is to make the random test cases working. But I misplaced the class for my translation attempt, so the given error occured. SleepingCode helped me getting this working. It should be possible to train the kata now.
I got the same Class 'PolynomialSimplifier' not found error. Could you please let me know how to get this resolved? It's a killer kata and I'd like to see some other solutions!
Hey bobtrigg,
the issue should be resolved. I misplaced the given class in the attempt to translate the kata to PHP. SleepingCode fixed this issue, so you should be able to train this kata now. If any other problems should occur, please don't hesitate to inform us again :-)
Hi,
The test_random gives me: Error: Class 'PolynomialSimplifier' not found
Please could you check?
Hi, I could infer that you are talking about the PHP version of the kata, is it correct? I'm reforwarding the issue to the translator.
Now it should be fixed. I'm marking the issue as resolved, tell me if the problem is still occurring.
Yes I tried the PHP version, but I still get the same error.
Getting the same error. After declaring empty PolynomialSimplifier class getting another error: Error: Call to undefined method PolynomialSimplifier::simplify()
Same error here, also in PHP.
I've contacted the author of the translation... I hope he can fix the issue soon.
Fixed! There was a merge conflict and the kata translation wasn't updated. My bad, I didn't noticed, don't blame the translator!
It works! Thank you!
Incorrect expected output for randomised test in JS version of kata sometimes when we have 0 koef in input.
For example,
xz-0bz
-0bz+xz
xz
Hi, the translator should have already fixed the problem now. I'm marking the issue as resolved, tell me if there are any problems.
A goodie!
why I have this error test_random Error: Class 'PolynomialSimplifier' not found
Hi, sorry for the incovenience. We are fixing the problem (see above for the discourse with 'kolossa').
An advice: mark the issues you encounter with the 'issue' flag, so it is easier for those who should fix that to spot your message.
The Haskell translation of this kata has some errors in the random tests. Some examples of the tests that I've been failing include:
It would be great if we could get this fixed.
I've had a chance to look at the Haskell test cases and debug them. Correct testing behaviour can be obtained by:
Changing the last line in the
showMember
function, so that:Becomes:
Changing the last line in the
main
function, so that:Becomes:
Hi, sorry for the late reply and the inconvenience. I republished the haskell kata translation following your advices (I thrust their correctness).
Thank you!
I spent A LOT of time on your kata, even after I solved it... ;-)
I made a version which can handle coefficients without variables, coefficients greater than 10 and variables with exponents (syntaxes allowed : ** or ^ ; but exponents have to be positives and written without brackets).
It might be interresting to confront it with others answers. Would like to create a harder version of the kata ?
It could be interesting to link those two (like SteffenVogel_79 did with his encryption problems : https://www.codewars.com/kata/57814d79a56c88e3e0000786 )
Thanks for this problem !
Hi, I'm glad you appreciate it :) I'm a bit busy lately, but I considered to "improve" it many times... In any case you could try to fork the kata using the solution you found ;)
Well... actually, I didn't really understand what the "fork" feature is... ;-s I thought this was to post better version of some solutions which where already posted (in the discussions). Maybe I missed something ?
I'm not really sure about that, but I think that you can fork solutions and katas. The last one should mean that you can add features and test cases refactoring another code. (https://en.wikipedia.org/wiki/Fork_(software_development))
Well, me again... While checking my code to improve it, I discovered it is actually wrong ! But it passes the tests all the same !
I suggest you implement some tests with coefficients bigger than 10 (in the previous version of my code, I inverted the strings so 31 becomes 13...)
Hello,
I encounter an error with the first of the "more complicated tests" but I don't have any clue of what's going on. Message error is :
"Traceback: in in simplify KeyError: 'c' "
How can I find what'going on, please ?
EDIT : well, the problem is in fact : how can I know what is exactly the test, in order to understand what cause the error with the key 'c' of my dict ?
Problem solved. Thanks to pizzx whose I use the proposal to debug my code. Which was wrong of course...
My solution can't pass the last testcase and I don't know what's going wrong there??
More complicated tests [('a', 3), ('a', 3), ('a', 31), ('a', 31), ('ab', -1), ('ac', 4), ('b', 1), ('bc', 1), ('bc', -1)] ✘ Sorry :( : '68a+b-ab+4ac' should equal '4a+b-ab+4ac'
Sorry, but there is something wrong with your code... I shouldn't tell you, but the input string doesn't contain any 31. Test it with some string created by you (with correct formatting, obviously), maybe that could help you spotting the bug. ;) Good debugging
thanks for your tip and i fixed the problem, It's really a big chanllege for me.I found my thinking almost the same with the best solution, but his code is much more simple and clean than mine. ^_^
Great kata! I'm kind of a novice with programming, but after 2 days of working on this, finally got it. Very rewarding and a good learning experience... trying to get a computer to do simple algebra.
This comment has been hidden.
Great kata, but my solution crashes on the advanced tests section with a strange error:
Advanced tests static ones PatternMatchFail (/tmp/haskell11663-13-305v6j/Codewars/Kirilloid/MultilinearPolynomials.hs:(20,1)-(22,43): Non-exhaustive patterns in function modMonomail)
What can I do to get more information on the cause of the test failure? Thanks in advance!
Good one, so thanks to "@SleepingCode". It's a really good exercise for Ruby newbies (like me;-)) - enjoyed to solve it;-)!
It seems there's something wrong with the hidden tests. I was getting random failures like (notice the "-+" in the expected string, which seems to me like an invalid thing):
Falsifiable (after 58 tests): expected: "-+5b+6x-17ad+cx-cy-10dz-5abd-8aby+6acx-acz+12adz-15bcy-5bcz-8byz-9cdy+6cxz-cyz-14abcd-abcy-18abdy+4abyz-12acdz-14acxz-5acyz+adxy+9bcdy-5bcxy-10bcxz-8bcyz+11bdxy+4cdxy-15cdyz+8dxyz-2abcdz-14abcxy+11abdxy-12abdyz-7adxyz-2bcdxz-10bcdyz-4bdxyz+7abdxyz-7abcdxyz"
That took me a while, nice kata!
Good kata, just a few spelling and grammatical issues. The title should be "Simplifying multilinear polynomials". There are also a few grammatical issues in the description that I can point out, if you'd like.
Yep, as your description says that was more difficult than expected.
Have you considered the following scenarios in your tests?
simplify('7-3x+4')
-> 3-3xsimplify('3c4a2b')
-> 24abcSuggestions are welcome, however I've already tried to consider them on the beginning, but this is my first kata and it was difficult enough for me as it was (I had not used regex before). I'll try to complicate it in the future.. ;)
This is a really fun kata and I enjoyed solving it. My only issue was that I ran into an intermittent bug with the random test cases in Javascript. Based on my understanding of the kata, I believe my solution should have been valid (and my solution passed after re-submitting it immediately after). I copied the test case output from a failed test to help in fixing it:
Testing for -0xb+0xbc+15x It should work for random inputs too - Expected: 15x+0bcx, instead got: 15x
Thanks, and keep up the great work!
Thanks for your appreciations :) Random test cases are difficult to implement for this kind of problems, in fact in my python version I've not implemented that :P, for other languages I'll ask the translators to fix that as soon as possible.
Sorry, I think there are some invalid tests for this kata. That's what I recieve, trying to submit it:
expected: "-+12a-7cz-15dx+11xz+9abx-12ady-3axy+11bcd-4bcxz-7cdyz+9abdxyz" but got: "-12a-7cz-15dx+11xz+9abx-12ady-3axy+11bcd-4bcxz-7cdyz+9abdxyz" [("cdyz",-7),("dx",-15),("cz",-7),("abx",9),("bcd",11),("",-1),("a",12),("bcxz",-4),("xz",11),("abdxyz",9),("axy",-3),("ady",-12)]
Also, behaviour with constant is not clear: in task definition we've been told that there would be no free constans, but test seem to generate examples with them and expect the program to filter them out, so input "2+a" have to be converted to "a". Correct me if I wrong :)
Sorry, can I ask you what language have you used?
Sure! Haskell
I see... I've already asked the haskell translator to fix that, thanks for your feedback ;)
Sorry for bad generator, will be fixed soon. Just need to sort merge conflict out - changes in descrption.
Now should be fixed, try to see if it works.
I'm still getting an error in the random tests due to constants (haskell):
Falsifiable (after 19 tests): expected: "4+8ay-9cd-3bxy-bxz-12cdy+11cxz+4dxz+8abcdxz" but got: "8ay-9cd-3bxy-bxz-12cdy+11cxz+4dxz+8abcdxz" [("cdy",-12),("cd",-9),("dxz",4),("bxz",-1),("cxz",11),("ay",8),("bxy",-3),("abcdxz",8),("",4)]
Thank you for quick responce! Alas, I cannot say for sure whether you fix helped or not - tests are still failing, but they are random, you know :) What is clear: you still generate some constans, something like "4+a" is possible for your generator. That should not be a problem for my parser, but it fails. Probably, there is an error in my code, but I guess you send me something like "1+-a". Could you check it for this set of values?
[("acdxy",-13),("bcdxyz",14),("a",-14),("bcd",13),("dxy",13),("cxz",-15),("cx",-2),("adz",4),("acxyz",-12),("x",7),("adx",2),("",1),("ax",-7),("bdyz",-12),("cdy",4),("ad",-10),("xy",-11),("bx",-7),("bcdxz",1),("acy",7),("cdxy",4),("abdy",-7),("acz",-5),("aby",-13),("abcxy",-5),("bdx",15),("acx",-9),("az",2),("dxyz",1),("bcdxyz",-12),("bcyz",1),("ax",12),("bdxy",14),("axz",3),("bdy",7),("adx",-8)]
simply avoid to generate void string like "". Actually, I handle this case, but internal reference solution give wrong answer. :(
expected: "7b" but got: "1+7b" [("",3),("",-2),("b",3),("b",4)]
Kata approved :)
First of all: thanks for the kata that I entirely enjoyed and upvoted with pleasure :)
I would recommend putting some extra edge case and a neat suite of random tests (I would gladly do that for you, in case you are interested).
Finally, translated it into both JS and Ruby, if you want to integrate them, so that many more users will be able to solve it :)
[Of course any possible issue with such a complex parsing kata is all my fault and for any trouble in the JS and Ruby version, just post under this comment so that I can be notified and fix it in time]
I'm very glad to know that you appreciated it :D
I accepted your translations with pleasure, and thanks for the link.
Thanks for your solutions, I'm learning a lot from them about regex :)
I'll try to repay you by doing some of your beta katas (whenever possible).
About random cases... I didn't put them yet because It's not straightforward to generate random "valid" expressions of that kind. I think I have made the tests in order to fill all the relevant cases; but there can be someone that cheats, it's that what you're saying?
Yeah, I know... if I find the time I'll insert them
I would gladly add random test cases for you: the first time it is not so trivial to build decent ones (but I must admit that for a first timer your testing suite was quite nice and well formatted).
About the relevant test cases... Well, I won't steal bkaes-senpai spotlight on this issue, but I'll just tell you that my first version of the code in both JS and Ruby passed ALL the fixed test cases, while it failed miserably with some random test cases I generated and that went way I had not forseen (two digits coefficients ending in 0, for example); I took some of the most relevant of those and added them to the fixed tests.
Regexes are like a nice drug: once you start using them, you just wonder how you did manage to breath without them before :p; and consider I never used them before CW ^^'.
Finally, no need to repay me: CW gave me a lot in more than a way, so I am just giving back to the community; if you really feel compelled to do something, help the next coder that you will find in need ;)
@GiacomoSorbi haven't really contributed to this site before, but is there any way to suggest spelling and grammatical improvements to the author? There are a few errors, including in the title
Post a comment in this discussion session and he should be notified.
If it is something blatant, I can do that too.
Post a new comment (not a reply to a comment like this one) and he should be notified :)
Thanks, I'll do that
Thanks, I'll do that