5 kyu
Diophantine Equation
1,613 of 4,865g964
Loading description...
Fundamentals
Mathematics
Algebra
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 ! I'd love to translate this kata to make it available in Scala 3, as only Scala 2 seems to be available, but I can't seem to figure out how to do that (when I try to add a translation, Scala doesn't show up since the translation already exists - but only for 2.13) Any idea how I could do that ?
You need to take the existing Scala 2 version and update it to Scala 3.
This article explains how to update a language version of a kata.
This post explains, more or less, what has to be changed in Scala tests to migrate them from Scala 2 to Scala 3.
I also recommend visiting the
#fixing
channel of Codewars Discord and ask there, because there is a couple of active users who know how to handle Scala updates.It was pretty straightforward, looks like this work :
https://www.codewars.com/kumite/67ce14f9ac545dfad6557b82?sel=67ce14f9ac545dfad6557b82
Let me know :)
Good mathematical average level kata!
Very hard and challenging katas.
Очень интересный ката. Автору списибо большое
This comment has been hidden.
An O(N^2) time complexity algorithm will timeout, opt for an O(N) time complexity algorithm.
JS Node 18. should be enabled with
mocha + chai
framework used and logs removedRuby 3.0 should be enabled
Enabled in this fork (+ KaTeX)
C#: method name should be
PascalCase
(Please refer to implementation of backward compatibility here )Python translation with new test framework
Approved by 🧙
could somebody please explain to me why x2 - 4 * y2 = (x - 2y) * (x + 2y)?
because a^2 - b^2 = (a+b)(a-b).
This is an algebraic identity - the difference of two squares
In your case, you can treat x =a, and b = 2y.
https://mste.illinois.edu/dildine/times/diff2sq.pdf
(x - 2y) * (x + 2y) = xx + x2y - 2yx - 2y2y = xx + (x2y - 2yx) - 2y2y = xx - 4yy
Please use markdown formatting:
(x - 2y) * (x + 2y) = x * x + x * 2y - 2y * x - 2y * 2y = x * x + (x * 2y - 2y * x) - 2y * 2y = x * x - 4y * y
or KaTeX:
(x−2y)∗(x+2y)=x∗x+x∗2y−2y∗x−2y∗2y=x2+(x∗2y−2y∗x)−4y2=x2−4y2
to write mathematical formulas.
Kata fails for C translation when list of pairs is not in sorted order, which is not an explicit requirement.
Look this in the description (that seems to be explicit, no?)
Not a kata issue.
You're right, I must have glossed over that bit.
So eager to post issues (at my poor C translations) you are reading too fast:-)
I'm just here to keep you sharp! :P
I am not able to import sympy. My solution involves:
from sympy.solvers.diophantine import diophantine
from sympy import symbols
https://docs.codewars.com/languages/python#packages
sympy is not installed on Codewars.
I can't solve this problem due to specific test 11. This is so weird that second pair of numbers require blanc space before them.It seems to me, that it shouldnt work like that. expected:<[[4505, 2252],[ [1503, 750], [647, 320], [505, 248], [415, 202], [353, 170], [225, 102], [153, 60], [135, 48], [103, 20], [97, 10], ][95, 2]]> but was:<[[4505, 2252],[[1503, 750],[647, 320],[505, 248],[415, 202],[353, 170],[225, 102],[153, 60],[135, 48],[103, 20],[97, 10],][95, 2]]>
I tried your code; it passes test11 but not test12 and it times out.
In C, why the returning parameter is a double pointer ?
Only God knows. Setup and allocation requirements of many old C kata are true mystery.
No, seriously now: what your solution has to return is a dynamically allocated array of pointers to
Pair
, where each pointer points to an individually, dynamically allocatedPair
. Don't ask me why, but there's more kata with such setup.Maybe just try it in another language.
Thanks!
I have added some comments and example code in the initial solution, hopefully it will be easier to understand what is required
I am trying to solve this Kata in swift. My code 900000009 gives me 11 valid results and you expect 6 only. Is there any other limits that are not revealed in the instructions part?
I was trying to find the right limits, but gave up. The limits really affect the time the algorythm takes to finish. Thanks for any tips.
My results are [(450000005, 225000002), (450000003, 225000001), (450000001, 225000000), (449999999, 224999999), (449999997, 224999998), (449999989, 224999994), (150000003, 75000000), (50000005, 24999998), (26470597, 13235290), (8823555, 4411752), (2941253, 1470550)]
This comment has been hidden.
COBOL translation.
Approved.
can you guys help me with this issue pls, before facing this problem, i have to duel with time out, but after changing idea, my result became this "Test Crashed Caught unexpected signal: SIGSEGV (11). Invalid memory access." Does that mean my idea have some problem and I have to fix and can anyone leave me any advise pls? Thank you!
please see if this helps: https://docs.codewars.com/training/troubleshooting#appendix-errorcodes
I think there must be some problem in my dynamic allocation (code C) but I can't figure out what is it. If I can see what the case is maybe I can fix this. Anyway thank you for your help !
what is a parameter of the function solEquaStr() int* length?
In the template solution you have a comment:
This comment has been hidden.
Thanks!
This comment has been hidden.
Found a new way to do it, complexity being O(sqrt(n)), this time it worked (you must really consider the hint if you don't already do). Otherwise it is a really good kata, hard on the math but it is what I prefer so it's cool.
All tests are passed. But it writes * Execution Timed Out (12000 ms) * because of which the test is not submitting. I tried it differently ... but still does not start up because of Timed Out. What to do?
Not all tests are passed because your code times out. It needs to be faster.
How many tests are there? Attempt writes * solequa (10 of 10 Assertions) *
When you "Attempt" there are 177 tests.
It's totally not clear what should be returned in Java when there's no solution.
Additionally, assertion messages are confusing af due to diff markers inserted by JUnit. Simple
return "";
results in:At least a sample test for input with no solution should be added, but it would be much better if assertion messages (or, ideally, format of the output) were improved.
See post by ozgurkircak below for some background.
OK. I note that 398 people found what to return but I plead guilty; nobody is perfect and especially not me.
I added a sample test for input with no solution.
Thank you I solved it now!
Thanks!
What is the difference between [[]] and []? Both are for no solutions but my soln could not pass the test because of that. expected:<[[]]> but was:<[]> In instructions it is said that for no solutions return "" or [] and that is what my code returned. What is wrong?
The difference is that the first is a two dimensional array that contains an empty array while the second is an empty array. Please say which language you're using or it's hard to help you.
I wrote my code in Java
I did not solve this kata in Java and I'm quite bad in this language. To me it's not clear in the description if you must return "" or "[]" in case of having no solution, seems strange tests expect "[[]]" as you say. I can't tell you. If I were you I'd simply try out to return "[[]]" and see...
Problem with Java is two-fold: One problem is that description is totally unclear whether you should return
""
or"[]"
in Java translation when there is no solution. The second problem is that JUnit tries to be helpful and fails miserably while doing so. JUnit adds diff makers to assertion mesaages when comparing strings, and these markers are represented by"[...]"
. So in this message:expected:<[[]]> but was:<[]>
it most probably means that you should return"[]"
, but returned""
, and JUnit in a very confusing way marked for you the place where the difference occurs.A sample test for a case with no solution would be helpful.
I tried that as well but it gave another error in the test. It is not clear what to return if there is no soln.
@ozgurkircak:
It is said:
If there is no solution return [] or "[]" or ""
. You forgot the"[]"
:-). I added a sample test for input with no solution.This comment has been hidden.
Fixed. Replace
for(a = 0; a <= ...
byfor(let a = 0; a <= ...
and your solution will pass.This comment has been hidden.
Asking for help is not a kata issue. I tried several solutions and had no problem; you should have a look at your code.
This is the third time I get : Failed Execution Timed Out (12000 ms) my code solves the kata. I can´t to submit does anyone know why?
Your code does not solve the kata, because it times out: https://docs.codewars.com/training/troubleshooting#timeout
thanks for the info
This comment has been hidden.
In R translation, the output is expected as list converted to String. That's a very poor choice of expected output.
OK it is your point of view. Anyway it is too late for a change. Sorry!
Any suggestions as to why this times out would be appreciated. Works fine in PyCharm.
This comment has been hidden.
Also, you should find an optimal upper bound to stop the iteration / early exit.
Clojure translation taken down?
It seemed but why? Mysterious... I republished it, tried several solutions and they worked.
Great Kata ! I remember not being able to solve it a year ago, back while coding in C++. Although i usually don't have big troubles with 5 kyu math type katas, here smoehow the math part was a little tricky for me. After a year of break, now in Python, somehow had better luck with this one :D
Is that possible to solve it on Python? I have always "Execution Timed Out", but all tests is accepted
Python Completions: 876
This comment has been hidden.
Certainly because I didn't find an easy way to test array of records with "CheckEquals" Pascal tests. Maybe too because of laziness: it seems easier to work with strings.
I haven't looked if there are assertions than can handle arrays, but even if there aren't, what does converting to a string have to do with the task? Nothing, so why not format it to a string in the tests? (Also, it doesn't have to be a record.
x
andy
are from the same dimension, so it can bearray [0..1] of ...
.)You could fork it with a function returning a list of two-elements arrays.
Why should I do it though? I wouldn't even have approved such a translation with strings.
Oh, I didn't say you should; it was only a suggestion; I said you because everybody knows your proficiency. I must tell that I don't really understand why this reject of "strings". Aren't they a human way of communication, understandable by everone? Moreover if - as you said - I have to format the result to a string in the tests... it's a double penalty!
But if you compare results as strings, you already do it in the reference solution anyway.
This comment has been hidden.
use differnece of squares to factor the polynomial
I did see the hint there. Just wondering if it means anything so far but I saw when I graph the hyperbola for n = 12, x = 4 is intersected at y = +- 1. Since we are only interested in positive answers, the intersection at (4, 1) seems to be leading me onto something maybe? EDIT : Well it definitely works for all the test examples. Just how to quickly get all quadrant I integer only plot points???? HMMMMM
i would suggest you use the factored polynomial to determine factors of n and see if they determine positive integers for x and y. i hope that doesnt give away too much
This may definitely help!
Factor translation submitted.
Approved.
testSolequa
should be changed tosolequa
in the initial F# solution.Fixed, thanks.
nice challenging kata
Thanks!
Using javascript, one of the tests tries 900000009 which is bigger than js safe integer limit and we need to use BigInt instead. But the interpreter doesn't support BigInt! So I think this is an issue with this problem.
How do you explain that 331 people passed the JS kata without BigInt and without raising issue? MAX_SAFE_INTEGER constant has a value of 9007199254740991... I am afraid that your code is on a wrog way, sorry and good luck!
This comment has been hidden.
Is it possible to solve in python? I am using only one loop, no additional packages. I limited the iteration interval, limited even and odd numbers for the different cases and even then it doesn't pass the time test.
Look at the top of the page: 727 people solved in Python.
on my computer for n = 90005 it takes only 10 ms ...but here ...
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Thannks!
I think the random tests in python are calling my function twice (when I run a
print(n)
it logs it twice). Why?my bad the tests print n anyway xD
In C++, kata produces unhelpful and very confusing assertion messages (see Lezh1k's post below), because it lacks stringizer for returned type. See this discourse for details how to fix it.
It is not only this kata; most C++ kata are "victims" of SnowHouse (and of CW that is using SnowHouse:-). I had already corrected some of my C++ kata but it would be helpful that the Github Codewars Wiki about C++ be more complete... since SnowHouse lacks lots of returned types.
Nonetheless I will add a "stringizer" for vector of pairs and let you know.
That's unfortunately true, but it does not change the fact that such kata have to be fixed, and user reports are good way to find out what kata are affected.
And when it comes to wiki, you can always add some information to it (it can be edited by community), but I wonder if it's really necessary since you can always check the docs of Snowhouse directly.
BTW I also think that you do not need to add stringizer for vector of pairs. I believ (did not check tho) that stringizer jsut for pair will suffice in this case.
Doesn't seem so.
Modified.
Expected: equal to [ [unsupported type] ] Actual: [ [unsupported type], [unsupported type], [unsupported type], [unsupported type] ]
Have no idea what does it mean and what went wrong %) Any hints?
Confusing message is problem with a kata, but it's caused by some mistake in your solution. I raised appropriate issue in a new thread above, but until it gets fixed, you won't get clear 'expected' value :( See this paragraph of FAQ on how to check the test input, recreate the test case locally, and try to find the error.
In this particular case it looks that expected array should have one element, while you return an array of four elements.
Coolio, now it's much easier to understand, that something is wrong in my solution. Also strange error ... Expected empty set for value -356473188? But a lot of values passt to this equation...
Maybe I don't understand some conditions of this... For example there were constraing (x >= 0 and y >= 0)... But this constraint breaks solution for n = 5 (set is {3, -1}).
Oh, sorry. I didn't see, than n is positive. So! In random tests we get negative integer and should return empty set? That's not right, but at least now I can understand this. Thanks for fix :)
This brought me back to my high school days with a nice page of math workings and some revision. Very satisfying when it was finished, thanks!
Thanks!
Seems broken for Haskell. Even a dummy function like
returns this error:
You must choose GHC 8.2. The kata has been updated.
Thanks. That way it is working.
This comment has been hidden.
This comment has been hidden.
You did not check whether
x
is also an integer. Also, what is the deciding factor in choosingn / 4
as the upper boundary?from sympy import symbols
from sympy.solvers.diophantine import diop_DN
ModuleNotFoundError: No module named 'sympy'
Give some advice please
sympy
is not available on codewars, also this task can be solved without use of any external modules.You should avoid using modules as much as you can.
It needs to enable Node 10 for JS because you cannot use BigInt otherwise which makes it unnecessarily difficult. I can't calculate x * x because it overflows. I am still thinking on how to calculate y at O(n) without x^2.
Can't you use a library?
You don't have to calculate "x * x" and there is no need for BigInt. 235 guys passed the JS translation without BigInt. Try to use the Hint.
Hey i need to know what number for basic case test i got this error, then i try find number, but [450000005, 225000002] and [2941253, 1470550] not same result of x^2 - 4y^2 = n
Expected <[][]int | len:15, cap:16>: [ [450000005, 225000002], [450000003, 225000001], [450000001, 225000000], [449999999, 224999999], [449999997, 224999998], [449999995, 224999997], [449999993, 224999996], [449999991, 224999995], [449999989, 224999994], [225000004, 112500001], [150000003, 75000000], [50000005, 24999998], [26470597, 13235290], [8823555, 4411752], [2941253, 1470550], ] to equal <[][]int | len:6, cap:6>: [ [450000005, 225000002], [150000003, 75000000], [50000005, 24999998], [26470597, 13235290], [8823555, 4411752], [2941253, 1470550], ]
You have the equation and 6 answers... you can use solve for n, using one of the expected test answers.
n = x^2 - 4y^2 n = 450000005^2 - 4225000002^2
Why order of answers is important?
Error. Expected {{4503, 2251}{903, 449}} but got {{903, 449}{4503, 2251}}
Description says : "...in decreasing order of the positive xi". Please, follow the description. Cheers.
My bad.
Hi; hobbyist programmer here (non-STEM background), wondering if anyone could point me in the right mathematical direction so I can fully solve this... Not looking for the answer itself!
Using some previous discussion posts, my solution now calculates the right answers with only one loop (x = n; n >= sqrt(n); x--) & (derive y from current x value), it's reaching numbers in the billions, but still timing out (running ~20 seconds on my local machine to solve the number I'm timing out on!!).
I've read about Diophantine equations, but my math is weak; so I'm still missing something - anyone have a non-spoiler / mathematical suggestion for me?
There is no need of a math background or of reading about Diophantine equations, only to know how to find the divisors of a number and to efficiently loop through them. Good luck!
Oooooooh
This comment has been hidden.
Hint - don't look for O(n) solution - it is kind of "brute force" kata.
I have had two working solutions for Python and both took too long. How much brute force is okay? Really hitting a wall here...
i am new to programing picked it up a few weeks ago so i made a code that works but its very slow it has 2 for loops and takes 30 sec to compute n = 10k
Same problem here. I do not know what to do.
Code should return empty solution, in case n is not positive. It is not straightforward from the description.
C++:
n
cannot be negative in this kataFrom the description:
This comment has been hidden.
Can someone explain how you would solve this? I am looking through other solutions and I really cannot understand how they were able to do it.
This comment has been hidden.
No, it just tells how (un)popular TypeScript is here. The number of tests in TS is of the same order of magnitude as in other languages.
Thank you sir for this great kata :D
Thanks!
This comment has been hidden.
It is a question, not an issue. Moreover which language? Note: there is no extra space before the final square bracket.
The language is C#. Yes, I know there is no space. When I remove the space (and the code shoud pass the attemp) it times out. When I add the extra space, it errors out. My code is executing in less than 1 sec on VS.
Something is weird with the Javascript tests. My code should be OK (the same algorithm passed in Python with no trouble whatsoever), but 4 of the tests give a message like this:
========== Expected: '96', instead got: '[[4505, 2252], [1503, 750], [647, 320], [505, 248], [415, 202], [353, 170], [225, 102], [153, 60], [135, 48], [103, 20], [97, 10], [95, 2]]' ==========
Out of curiosity, I added this to the code: if (n == 9009) return 96;
and then it turns out that the tests expect the value I pass normally:
========== Expected: '[[4505, 2252], [1503, 750], [647, 320], [505, 248], [415, 202], [353, 170], [225, 102], [153, 60], [135, 48], [103, 20], [97, 10], [95, 2]]', instead got: '96' ==========
Can somebody help explaining what is going on? I do not have very much experience with Javascript yet.
This comment has been hidden.
This comment has been hidden.
0% programming, 100% math. Formatting the answer string is pointless and annoying.
so true, after this kata i use filter with no math in
Finally getting to the answer was so satisfying (:
OK, good!
Hey guys, I am passing all the sample test cases but am constantly timing out.
For me, my algorithm runs x from square root of n up till n, and for each iteration of x, runs another y from 0 up till half of x.
i.e. Sqrt(n) <= x <= n and 0 <= y < (1/2)x
I got the above equalities by playing with the conditions provided. What have I missed out that is making my loop so inefficient?
Check the hint ;-)
Does the hint help to do away with the need for double for-loops? I initially thought the math was supposed to be used to narrow down the loop conditions for x and y in the original post. Am i mistaken?
Yes, you only need one ;-)
This comment has been hidden.
It often means a problem somewhere in your code. 105 guys passed the C++ kata.
The test works fine. It only does that if you're wrong (it simply prints "Test Passed" otherwise), but that doesn't take away the issue that it has problems with printing an
std::pair
.It prints "unsupported type" for both the user's answers and the expected answers -- that can't a problem with the user code.
I did pass the test eventually, but it was difficult not being able to see what your program returns and what the expected answers are.
This comment has been hidden.
"potential_factors = (1..n).to_a"
I think you can do a bit better there.
Great Kata, thank you! Maths is gorgeous!
really nice kata, what a challange !! thank you
Thanks!
I think this kata deserves to be a 4 kyu or a 3 kyu problem because it took me much longer to get a fast solution than a 5 kyu problem normally takes. I've seen other people comment similarly which is what prompted me to say this.
Overall a very satisfying problem to solve I just think its difficulty level needs to be changed.
It is a moderator who gives the kyu, not the author.
I have some sympathy - I don't agree these can both be 5ku:
https://www.codewars.com/kata/scramblies/java https://www.codewars.com/kata/diophantine-equation/java
Kata's rank can't be changed, closing.
No random tests.
Please which language? Maybe I am not well awake but each language seems to have random tests.
More than half of them:
Oh! Sorry! It seems that I was not awake... I believed "Fixed tests" because it happens I forget them. This kata was written on
May 10, 2015
. At that time "Random Tests" were not very usual. As it was, the kata was approved by @jhoffner. Later was written a "Rust" translation but the random crate didn't exist at that time at CW. Recently I wrote a "shell" translation and I put random tests. I have not enough time to come back to my old kata and add random tests. Nevertheless I will be honored if you have the will and the time to add them.Little by little, AFAIK all languages have random tests except Clojure (see Bug report #1270 https://github.com/Codewars/codewars.com/issues/1270).
who do you guys think is a better coder? g964 or Voile?
never choose the weeb.
Results are matching for run sample. But when click on attemp following error comes.
Process was terminated. It took longer than 12000ms to complete.
Same thing happening in few other katta solution submittion.
Not a kata problem but certainly a CW one.
This comment has been hidden.
This comment has been hidden.
I have some troubles with the applying my solution. As I increment from 0 to ... I have a mismatch with the required result.
[[903, 449], [4503, 2251]] should equal [[4503, 2251], [903, 449]]
The same thing with this [[95, 2], [97, 10], [103, 20], [135, 48], [153, 60], [225, 102], [353, 170], [415, 202], [505, 248], [647, 320], [1503, 750], [4505, 2252]] should equal [[4505, 2252], [1503, 750], [647, 320], [505, 248], [415, 202], [353, 170], [225, 102], [153, 60], [135, 48], [103, 20], [97, 10], [95, 2]]
Is the proposed answer correct or not? All other tests before specified are passed
The order of results requirese on xi
Also, opt for an O(N) complexity approach , you will also need to find the upper bounds before stoping the iteration of your loop.
Using C, I question why the return type is
Pair**
. I would expect it to bePair*
so I can allocate the array withPair *dio = malloc(10 * sizeof(Pair))
, resize as needed, andreturn dio
.That is easier than needing a new malloc call for every pair.
This comment has been hidden.
This comment has been hidden.
Kata is solved. So, nevermind. =)
If I simply increase the range of my search by 1 it times out. I think it would be good if at least the passing tests were printed out before it times out. That way we know which test timed out and can optimize for those tests. I've also noticed that simply adding an else block for a case where [] is the answer causes a time out!
Print the input.
I tried printing the input, but even then it simply times out. I think at least the first few tests would be simple cases and I expect my code to not time out in these cases.
Even with "Example Tests:" ? If needed keep only the first one of "Example Tests:".
Well that's the thing. The example tests all pass. It's only when I attempt the other tests that it times out.
expected:<[[4505, 2252],[ [1503, 750], [647, 320], [505, 248], [415, 202], [353, 170], [225, 102], [153, 60], [135, 48], [103, 20], [97, 10], ][95, 2]]> but was:<[[4505, 2252],[[1503, 750],[647, 320],[505, 248],[415, 202],[353, 170],[225, 102],[153, 60],[135, 48],[103, 20],[97, 10],][95, 2]]> eh...i think this info is not "correct"
Thanks for this. I like Kata for which brute force times out and makes me think about the math. Plus, it's one of the few that I could solve with a (convoluted) one liner.
Thanks for your post!
I get to test 23 using PHP and it times out. Sigh. I'll keep working on it. Did others struggle with processing time?
Initially, but I managed to find a fast enough way (in PHP).
I am completing this problem in C++, and whenever I sumbit I get no errors, 0 tests passed, 0 tests failed, and no way to proceed.
Is there a problem with the C++ test suite for thsi problem, or has anyone experienced this problem before?
22 guys passed the C++ kata. There are no problem with the tests cases. You can report your problem at CW: Go Forum (on the left) and then bugs.
Ok, thanks for the info, I'll head to the issues boards. My C++ solution goes through ok now so I assume it's a back-end issue.
It's a neat little problem, thanks for setting this kata, I enjoyed solving it :-)
I would suggest the precision be made that n should be strictly positive (n > 0) and not simply positive (n >= 0). because the eventuality of n = 0 yields an infinity of (x,y) solutions statisfying the equation (every couple (0,x) where x in a multiple of 4 for instance)
I think in English a postive integr n is > 0.
Well, that was tough. I spent all day to make my solution. Thank's a lot, nice kata!
Thanks for your feedback!
This comment has been hidden.
It's not a bug of the kata! Report that at Codewars: https://github.com/Codewars/codewars.com/issues. It has already happened.
Ok, thanks. I'm a bit newbie here so I haven't know where to respond =) Thank you for link.
This comment has been hidden.
Thanks for your encouragements!
Hint and mathematics is very important!
Rather true-)
I'm I right in assuming the hint helps to shorten the loops? I run out of time with my current approach...
This comment has been hidden.
Print the input...
This comment has been hidden.
In Java there are problems to check array of arrays at CW hence a string.
The description says:
and I can assure you that all the tests are in the same order: "in decreasing order of the positive xi".
About half hundred Codewarriors passed the kata in Java without problem so I don't understand yours unless Codewars is very tired:-)
I was encountered the same issue. It will not accept my answer because our order is different :|
[[903, 449], [4503, 2251]] should equal [[4503, 2251], [903, 449]]
Did you resolve this problem? I have the same thing
I can't help but feel this deserves to be in a harder kyu; the programming itself is trivial but the algorithm relies on doing a bit of maths. Excellent kata...
Thanks!
I don't know what the problem=( Test 26 - I got 15 pairs of numbers. I can't figure what result must be=(
Please fix problem with int32 overflow - are these numbers suitable or not? different test cases require different numbers
Which language please? There are no problem with the tests but maybe with your solution:-)
C#
This comment has been hidden.
Why Int32? Did you see the signature of the function in "Your Solution"?
[755918, 6717] is not a solution.
Best kata I've faced so far!! I've spent many hours to find an algorithm that could run in reasonable time, and then, finally, I've focus my mind on the hint. Very nice exercise, congratulations!
Thanks for your feedback!
This comment has been hidden.
I didn't remember about what I saw you:-( I'm very sorry but all the tests have the same format as said in the description:
left bracket left bracket number comma white-space number right bracket comma white space left bracket and so on... Test 21 has exactly the same format as the other ones. Could you give between three backticks what you get when a test fail? (only one example!)
The 3 backticks are "```" (google "markdown" if you don't know). On a newline put the 3 backticks, then a newline, then your text, then a newline, then once more the 3 backticks and a newline... I ask you for that because it could be a problem with white spaces and in normal text they can't be well seen. Put completely, for only this test 21, what you got in the CW console.
Thanks for your time! The test 21 is:
Maybe you can post your solution (mark it as Spoiler!). I will try it.
Thank you, I sorted my problem out, just running out of time now, so I need to optimize.
Running through up to and including Test25. So just the last 3 tests to conquer.
Don't take the habit of putting an issue before knowing it's a problem of your code or of the kata:-) Tell me when you succeed!
This comment has been hidden.
This comment has been hidden.
I solved this kata, but it took me too much time because I took the same approach as you, just solving the equations and trying to reduce the search space, which is too slow... the non spoiler hint is that you need to consider the hint given in the Kata...
This comment has been hidden.
This comment has been hidden.
Thanks for the feedback!
Shouldn't it be somewhere noted that A that is mentioned in description is actually parameter n (at least in JS code it is named n)
Description modified, tanks!
This comment has been hidden.
You are basically brute-forcing the issue. By using the hint given in the descrption you can get a huge reduction in the possible solution space.
I'm sure, that there is a problem with the test case "Test11" in Java: there are some extra brackets and no comas between solutions, but it is required in task description
I can't see any problem in Java test 11, there are no extra brackets and there are commas. Can you be more explicit? Tests are almost the same in all languages.
test11(DiophTest) expected:<[[4505, 2252][[1503, 750][647, 320][505, 248][415, 202][353, 170][225, 102][153, 60][135, 48][103, 20][97, 10]][95, 2]]> but was:...
I don't know where your extra brackets come from. They are not in the test cases and there are commas between answers. Maybe Codewars has problems... try later. Tell me if you succeed, good luck!
Well there's an easy answer for this.
All the tests are using the following form:
This means that the expected result is actually your result not the true answer. So it's also your code which isn't generating the commas. ;)
Sorry for that!-( I corrected it, hopefully the tests are now in good order! As far as I see my code is generating the commas...
This comment has been hidden.
Sorry to say, but I think, in Java tests one of them is wrong. My code works fine except that one, and to check I calculated with hand, an mine is still correct. You need to check that. Test number is 28.
Thanks for the feedback but Test 28 is the same in all languages with same result in each, nobody complains so I have good reason to think that it is not wrong:-)
Interesting, meh, i will check again then.
I too can't pass the 28th test. Check please!
Test 28 is the same in all languages and is right. Almost 40 people passed the kata in Java without problems. I just tried again my solution and two others and they pass. So check your solution please. Test 28 is with the biggest number.
am getting a timeout error while submitting. can someone help me out? for the same test case it works if I add it to my test cases. what am I missing?
0 is not positive integers.
Where did you see a 0?
In the first series test case, there were solutions like [(4,0)]
Yes you are right, in English a postive integr n is > 0. In other languages n positive means n >= 0. I will correct the description, thanks!
It's been 9 months, and the description still disagrees with the sample cases.
The description now says:
This kata will be much more challenging, if test cases included really big integers.
I don't know if the test cases were updated since your comment, but I found this kata quite hard for a 5 kyu. My first solution was in O(n²) and didn't pass, granted. But when my second attempt in O(n) didn't pass either, it took me a while to find a working solution. I would rate this 4 kyu.
Please which language? I didn't think the test cases were updated.
No, I do not think that tests were updated too.
I's possible to do it faster than O(n) if by that you mean trying every possible value for x (or y). The key is making use of the hint in the description...