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.
could be:
return (braces == '');
This comment is hidden because it contains spoiler information about the solution
Thanks for the contribution & apologies for my haste in submitting
This comment is hidden because it contains spoiler information about the solution
Indeed true. You'd have a point saying I'm over-complicating things!
OTOH, there is that situation where a learner can use the syntax of a language feature, but doesn't know when the feature is appropriate - hence my comment.
Including the right degree of 'real life context' is a part of martial arts kata. Kata have the essence of an application for a hypothetical situation: they're taken from real life, but not messy like real life.
Hence (a martial artist might say) kata should have some degree of real-life context. And what is the essence & what's application details? That's a matter of discussion and discovery.
Again: I'm overthinking things. A simple exercize in syntax and some trivial fun is also useful of course!
Thanks for your comment.
Thanks - & hope some suggestions make it into the kata :-)
It's a nice kata: The background & history are very interesting. But I'd like to suggest an edit to the description: I think it makes it clearer. Of course: feel free to take/ignore any of these suggested edits!
One of the first algorithm used for approximating the square root of a number is known as "Hero's method", named after the first-century Greek mathematician Hero of Alexandria who gave us the first description of the method.
The method approximates the square root of a number n by taking an initial guess x, and an error e; and repeatedly calculating a new approximate value x using: (x + n / x) / 2 ; we are finished when the previous x and new x have an absolute difference of less than e.
We supply to a function (int_rac _) a number n and a parameter 'guess' (a positive integer). For this kata the parameter 'e' is set to 1.
Hero's algorithm is not always going to come to an exactly correct result, especially when setting e to 1! For instance: if n = 25 we get an answer 5 but for n=26 we also get 5 which is obviously incorrect - but as it is within our error range it is a solution.
The kata is to return the count of the progression of approximations that the algorithm makes.
Reference: https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method
Some examples:
int_rac(25, 1): follows a progression of [1, 13, 7, 5] so our function should return 4
int_rac(125348, 300): follows a progression of [300, 358, 354] and so our function should return 3
int_rac(125348981764, 356243 ): has a progression of [356243, 354053, 354046] and our so our function should return 3
Notes for JavaScript, Coffescript
Don't use the double bitwise NOT ~~ at each iteration if you want to have the same results as in the tests and the other languages. You can use Math.floor for each integer approximation.
This comment is hidden because it contains spoiler information about the solution
Only a small thing, but there's a test message: 'Bla'.
Problem states we have to make at least one iteration so 55 -> 110, which isn't palindromic so we have to proceed.
1: yes: 1 + 1 -> 2, which is single digit, which by the problem's definition, is palindromic.
good use of the Counter!
Thank you for the feedback. I should've checked: it's such a popular algorithm after all.
Decorators separate out validation logic from business logic: this makes the code cleaner.
I've made three decorators - one for each rule: as validation rules can change and we can re-use them.