Python range function exlude the last digit. Example: range(0, 2) => [0, 1], therefore limit+1 is needed to include the last digit.
range(0, 2) => [0, 1]
For more info:
Don't get rid of them like this, your if statements run faster than gratuitous dicts.
Don't feel bad about your if statement, this solution with an unnecessary dict creation is slower than your if block.
Great simple solution. Love it. Left/right in one dict ... and the return statement. You know Python. :)
Boom! So clever!
This comment is hidden because it contains spoiler information about the solution
so functions in python are first-class objects -- you're able to set variables equal to them just as with any other object type. lambda is a way to define a function without a name and in this case, the unnamed function takes one argument, n, and we return the expected series. So generateIntegers is now a variable that is equal to the function and generateIntegers(6) would yield the expected value as a consequence of that.
Apologies for the slightly roundabout description but I think I've avoided writing a spoiler, maybe, mostly..
I'm using this language feature in an admittedly gimmicky way (to write one-line solutions to codewars problems) but it is a very helpful language feature (the first-classness of functions) -- many other languages treat functions as different (and don't allow this sort of assignment.)
how do you run this exactly or input the value n in the function? thanks!
Forgot you could use a step parameter with range!
This answer is genius
if comedy existed through code, this would be it. Gave me a good laugh XD
Btw, I didn't mean to be arrogant. I'm new to this website and might be wrong. Still, in my point of view, this is a way of cheating, and I provided 3 arguments as to why I think so. I would appreciate it if you could present any counter arguments.
But the problem definition does not specify an upper bound for the values of m and n. The only way to ensure that the hardcoded values are broad enough is through trial and error, what thus only garantee that the program is correct for the presently given tests, which do not represent the whole of the problem (as of the description). If tests with higher numbers were added, for example, it would break.
That said, even if the warrior had to write the actual code to find the numbers, as you mentioned, that code is not included here, and thus it's bypassing the execution time constraint. As for your precalculation argument, I imagine one can still run a precalculation routine here, only once, by using memorization, unless the variables are reset and the code is reinterpreted between each test, which I find unlikelly.
Think of it like this: If I were to print out all the tests of a problem, write a program which can solve it elsewere, compute all the awnsers and present here anther program which simply access a hardcoded mapping of question->awnser, I would be cheating, right? Would work though, and fast. This is, partially, in my opinion, what this solution does.