Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
OP solved the kata
Benjamin, thank You very much for this suggestion!
If fact, I was playing a while with replacing 'i' with 'j' and didn't commented in the end.
At my desktop this unoptimized code runs fine (8 cores CPU and 32 GB RAM), but in this environmnet it stops after passing medium tests:
Medium tests (3 of 3 Assertions) OK.
But by large tests I've got twice well-known STDERR: Large tests Execution Timed Out (12000 ms).
So maybe instead of two for loops (by i and by j to summarize elementVal = 1 * i + 2 * j + 1 ) should I switch to an generator plus lambda function ...?
Well, its time to open math books or Calculus manual and come back to Mr Euler's elegant solution...
Hi @Bodeq - the error that you encounter
Max Buffer Size Reached (1.5 MiB)
is not due to your algorithm, it is simply due to the fact that you have aprint
statement:print('element a/',i ...
<- in your main code.Codewars test framework stops due to "Max Buffer Size Reached (1.5 MiB)" - because with large tests your code will
print
a huge amount to console.Just remove this line (or comment it) from your code and you should avoid this error (now your code should be able to run up to the full
12
seconds allowed for the tests in Python).so it is supposed to be doable just returning the number using only 1 line with a formula in the function?
i've used geogebra and done regression analysis using all types of regression.
even wolfram can't solve it, nor point to a direction.
I am afraid that i started in the wrong direction and got stuck.
It is possible with a single mathematical formula.
Hi! I was trying with the double for loop, but after 1 sec. a standard error has rised ( Error 137: Max Buffer Size Reached 1.5MB), and now I see that I need a formula rather, not lopp. Well, finally I have understood the meaning of this final note about avoiding a brute force ...
Thank You for this tip!
I've just noticed that not only the print () function was redundant as a result.
I stared at the sample answer and absolutely wanted mine to be the same as a string.
Therefore, I have added single apostrophe on both sides. So the answer was the same on the printout.
I was confused that as the correct output our Sensei gave the result in double quotation marks,
["hay", "junk", "hay", "hay", "moreJunk", "needle", "randomJunk"] -> "found the needle at position 5" -
instead of this text without them. The better is the enemy of the good. ... B
The
return print(answer)
is wrong, and makes your solution return wrong answers.This comment is hidden because it contains spoiler information about the solution