Ad
  • Custom User Avatar

    Similar, but more syntactically elegant, than mine. I believe that it's either choosing the correct number in the sequence pre-emptively (by using min(), for instance), or guesstimating parameters that will work against these tests but do not generalise/scale.

  • Custom User Avatar

    Choosing the next smaller number in the sequence is what I consider the most elegant solution, cheers (on the contrary, I had to sort afterwards).

  • Custom User Avatar

    Why 35, 25, and 15? By trial and err?

  • Custom User Avatar

    d>''<b

    is a double thumbs-up!

  • Custom User Avatar

    @cahyareza

    if x < len(s) - 1
    is the same as:
    if len(s) - x > 1
    meaning that the cursor (x) has to be before (<) the last position (len(s) - 1), in other words at the penultimate position at most, and in this case you want a slice of 2 (s[x:x+2]);
    otherwise, if your cursor is at the last position, you want the last character plus an underscore (s[-1] + "_").
    You are safe since you're stepping 2 by 2 (in range(0, len(s), >>2<<)).

    Also remember that positions start with 0, so each one is "position - 1" (the first one is "1 - 1 = 0", the second one is "2 - 1 = 1", ..., hence the last one is len(s) - 1).

  • Custom User Avatar

    I actually love this one as it fits better in a functional programming mindset.