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.
oh
I believe len() is not calculated when you ask for it, but when the string changes. Don't change the string and ther is no charge. Strings are immutable, therefore str(value) will have the same id() no matter where you use it. As both loops are executed the same number of times, they will have the same number of conversions to int. The for loop may be slightly faster, and possibly easier to read.
Someone please correct me if I'm wrong!
Oh man... I wish I'd spotted this earlier! My solution was a lot more convoluted spotting a pattern and connection between the supplied row number and the first number on the row rather than the simplest solution of "what is the answer in comparison to the row number"...
Nice work!
Repeatedly converts value to str in loop and calculates the link - better to sacrifice the one-liner and store the conversions in variables outside teh generator.
I understand what do you mean. I am not presenting well. I agree that it is the best way for the computer to run.
I just want to say that not all know this method. It also require your math skill.
Not everyone has good math skill, but this method is the most fast way and clever.
I'm going to have to completely disagree with you banny127: this is the best answer because it was calculated before coding.
Math first; code later. Your CPU will thank you.
Programmers need to have a ton of tools in their toolbox, and your casual dismissal of "algebra" is, frankly, terrifying--given that all programming boils down to logical/mathematical computations.
That depends on the view of what is the best solution. However, in most computer algorithms the best solution (out of all that give correct results) the best is where is minimum used memory & CPU time. This is a solution in constant time because there was a previous analysis with pen & paper. That is what I call a real optimization - the author found a way of different solving of the same problem using less resources.
This comment is hidden because it contains spoiler information about the solution
Not clever but correct!
Good work!
After few days that code has been submited.
As far as I know there are no errors in the Python tests; nearly 50 Codewarriors got the Python kata.
This comment is hidden because it contains spoiler information about the solution