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.
Why is it slower?
[25,25,25,100... results in $100 in the clerk's drawer, but in the form of a $100 bill isn't useful for making change (unless someone shows up with a $125 bill :-) )
That is an improvement. Technically, it still is ambiguous, since
(x+n//x)//2
does not always give the same result asmath.floor((x+n/x)/2)
. (i.e. Isn/x
cast to integer, or just(x+n/x)/2
?) For example, 24267650325993838580 not only converges one step slower for(x+n//x)//2
it doesn't even arrive at the same result as(x+n/x)//2
. There are many such values, typically with true square roots very close, but not equal to integers. None of your test cases give different results for the two methods, though, so your updated language is probably good enough.As an aside, I also notice that if you use integer division for both divs, there are some input values that will never converge to less than one. 120 is the first one greater than 100:
(10+120//10)//2 = 11
--->((11+120//11)//2) = 10
There are ~300 below 100,000...but the algorithm provided
(x + n / x) / 2
doesn't work in general - only in languages that interpret "/" as integer division, rather than the common meaning. What would be the harm in clarifying which version of division is being checked against? If you don't want to use the word "Python," how about "repeatedly calculating a new approximate value x using: (x + n / x) / 2; (Assuming "/" represents integer division.)"It is not clear that expected implementation of Hero's method is to use integer division. In Python 3, using
(x + n / x) / 2
as in the description, the routine will fail in some test cases. Suggest adding to the description so that it reads "repeatedly calculating a new approximate value x using: (x + n / x) / 2; (Assuming Python2 integer division.)"I hadn't read that line about math.floor, because it is preceded by "Note for JavaScript, Coffescript, Typescript...." Didn't know that there is information needed for Python solution also.
Given the usage case, it seems totally reasonable to have an empty "histogram." The image could have a huge, scary black bear halfway out of the shot on the left edge - then there is no white rectangle in which to place text.
I am seeing the same result as Arcuo. Hero's Method converges in 29 steps for the input parameters given in that test. I printed out each step and counted them. I double checked this with excel. If the five of us who are getting 29 were instead writing code that converged too slowly, I would think we are doing something wrong. As is, we are converging faster than others, and I cannot see how we could be incorrect.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Ugh. The instructions should be updated to explicitly state the intended output for an empty array (since it is expecting something that would normally be considered "incorrect.")
The very first edge case for Python is an empty array. There is no average for an empty array, and the description does not say what should be returned.
NaN
?Undef
? (I really hope it isn't expecting0
!!)Ok. This is the first time I have come across complex numbers in Python, so I learned twice here - Thanks!
Loading more items...