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.
It seems like there's some floating point errors with the random tests:
E.g.
Expected: [0.29836609045702106, 0.18020364669666114, 0.12242481648117452, 0.0942457968269003, 0.08074828321098745, 0.06961875443997158, 0.05541084537058963, 0.053279659010182334, 0.045702107506511956]
instead: [0.298366090457027, 0.18020364669666242, 0.12242481648117365, 0.09424579682689997, 0.08074828321098737, 0.06961875443997172, 0.05541084537058983, 0.053279659010182515, 0.04570210750651206]
The elements of the arrays are accurate to 1-e14, yet tests still fail. I'd avoid comparing two floating point numbers directly.
A quick fix to solve this would be to map the user solution with
.map((v, i) => (v <= expected[i] + 1e-7 && v >= expected[i] - 1e-7) ? expected[i] : v)
. This will change each element to the expected element if it falls within a range of +- 1e-7.You can validate source code.
isMathySolution(require('fs').readFileSync('/home/codewarrior/solution.txt', 'utf8'));
:)This isn't affected by people using string manipulations, right?
I asked why you'd want to encourage people to do it 'math-y' because I don't think it adds much difficulty or improve performance. Isn't it just some
log10
,pow
,floor
?This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
I think I've got it updated using @kazk's idea. I've also scaled it up or down by multiples of 10 randomly.
Thanks, that's a good idea. I saw that you'd done that and was wondering why.
@sappharx, I also recommend giving user a copy of generated array. I've seen many issues opened by people who chose to modify the input for no good reason :(
I think there's something wrong with the Kata Editor. Every time I run "validate solution", the top of the output window shows something like
Time: 379ms Passed: 0 Failed: 0 Errors: 1
and there's nothing in the output console (even when nothing has changed from when I published it yesterday). So, for the moment I haven't been able to update usingassertDeepEquals
yet.Also, when the editor is working again, I'll update the random tests to have a Benford-ish distribution.
Yeah, the documentation is bit outdated :( But many newer kata uses it.
You can see the source here: https://github.com/Codewars/codewars-runner-cli/blob/master/frameworks/javascript/cw-2.js#L374
Thanks for the suggestion, I didn't see
Test.assertDeepEquals
in the test framework docs. I'll try to use that instead.Maybe probability can be used to generate the first digit. For example you could fill in an array with 9 ones, 8 twos, 7 threes... and choose first digit from that.
Btw here is one basic way of creating random numbers 0-1 that have an inverse probability of being picked from their value.
So smaller nums get to be picked more likely.
Nice one.
Would it be possible somehow to generate random test input that shows a Benford instead of a uniform distribution?
(Well, yes, of course that's possible. But what would be the best/easiest method to get a population distributed across several orders of magnitude?)
(Someone make a kata out of this? :P )
Great Kata, keep up the good work :D
Good job with your first kata, using appropriate test functions and includes random tests :)
One suggestion is to use
Test.assertDeepEquals
instead ofTest.assertSimilar
because it has problem dealing with signed zeros. For example,Test.assertSimilar([-0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0])
fails :( I don't know how/why signed zero can get included in the result, but I prefer safer option and it may prevent potential issues. So maybe consider changing that if others agree with me.