Ad
  • Custom User Avatar

    This one has constant comlexity O(1), while an iterator will have at least linear complexity O(n).
    While this doesn't make this automatically more efficient for small values, we can optimise this solution by using bit operation for deviding but the compiler already does that for us.
    So that means this solutuon needs 4 arthmic operations to execute, while the iterator solution needs at least n arethmic operations, meaning that if n is bigger than 4 the iterator solution is already worse.

  • Custom User Avatar

    Yup that one should be best practice

  • Default User Avatar

    I feel this one more performant for very large n, under the assumption that sum() function for iterators goes through n elements.

  • Default User Avatar

    Good point. This solutions does not correctly handle upper camel case.

    The test_solution_randomly function strips the uppercase letter from the start of the sentence with:

                sentence.push_str(&word_selection.next().unwrap()[1..]);
    

    So I take it this problem is only intended for lower camel case.

    The problem statement should probably be made to be more specific.

    I see someone already reported the issue:

    https://www.codewars.com/kata/5208f99aee097e6552000148/discuss/rust#6181ac3bac59440057e75f57

  • Custom User Avatar

    Doesn't this function fail to account for a string that may start with a capital letter?

    Take the example "CamelCase", this function output " Camel Case" instead of the intended "Camel Case".