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.
This is not enough information. In addition to the required precision, the kata should also specify the rounding method (e.g., half-to-even), and when to apply the rounding (e.g., on the sum at the end).
This comment is hidden because it contains spoiler information about the solution
Thanks for bringing this to my attention. I agree they should be treated as integers, but IIRC six years later, at the time the solution tests didn't treat them this way.
Marking resolved.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Python
Correct solutions show red on the
Array =
portion of every random test. TheCommand =
portion shows correctly. Example:Fixed test error messages are wrong and inconsistent.
The first error message says the initial number is
7
but it is-7
. Tests 2 and 5 only provide the results and not the initial conditions.This comment is hidden because it contains spoiler information about the solution
Beautiful and fast solution.
Just to expand on this a bit for those who don't know, there are many issues with rounding and computers.
The three most relevant here are:
What this means practically for kata is that without a clear definition of what it means to round, it can become a game of 'guess how the kata author rounded' and become a problem to debug both kata solutions and the kata itself.
FWIW, Python's builtin
round
rounds .5 to the nearest even integer by default (withndigits = 0
orndigits = None
). Withndigits > 1
it looks to the digit to the right of the 5 to decide how to round, but because of (1) above, it can appear random or arbitrary.One solution to this problem is to not check for exact answers, and instead include a fudge factor:
assert abs(actual - expected) < fudge_factor
.Random tests or spec solution in Python is bugged. 1952 has an abundance of 2, is greater than 1950, and is in the interval [1, 1955].
This comment is hidden because it contains spoiler information about the solution
All programs have constraints on input. In this case, there can only be two distinct values in the array. We can certainly program a solution to return an array of any number of unique values; but that's a different problem and the solution to that problem will be less efficient when applied to this problem.
To my knowledge, the only time
math.sqrt
would be faster would be when you're doing a large number of square roots. Probably more than you'll see in a kata (but don't quote me on that one).Generally I don't worry about it unless I'm doing something that is centered around a lot of square roots and I'm having issues with optimization. If I do worry about it, I have to test it anyway.
Loading more items...