What does the %d do? Does it insert whetever is after the %?
Why is this answer considered nicer than the second best solution here?
I intuitively prefer the .format solution below - any views?
Two good points, but if it were production code, you'd be more cautious.
I admit to using the quick solution, but I see fragrantbeauty22's point.
There may come a day when some entity trips up yet you keep your stride.
Don't get discouraged, this is the way we all learn.
You have to write your own "for loop" iterating over all elements at least several times before you start using shorter built-in methods.
Only this way you can learn and understand how this methods work internally and be aware of their limits as well.
Good info. That makes me happy. That the solution I wrote would not have that error. But then, the problem was stated with the condition that the needle will definitely be there in the haystack [from description: but containing one "needle"], so i guess its fine. We always have to stick to the specification, and conditions beyond it don't need to be handled I guess.
I feel like that for nearly every solution I look at lol. Now I simply think of the shortest way to write the code everytime I start a new kata.
This comment is hidden because it contains spoiler information about the solution
As a newbie, it feels very frustrating taking a looong time to come up with a working solution and seeing this kind of answer at the top. Hope I get at that level some day.
Good job, guys.
So easy and concise, can't believe I hadn't thought of it.
Thanks for the new translation
if (randint(0,1)==0) string.splice(randint(0,string.lenght-1),0,"abcdefghijklmnopqrstuvwxyz"[randint(0,25)])
if (randint(0,1)==0) string.splice(randint(0,string.