Ad
  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    What does "%0${it.length}d" mean? Is it Regexp? Can't understand how it works.

  • Default User Avatar
  • Custom User Avatar

    Don't want to sound like a teacher... :) But sorting twice and specifying a Comparator with two criteria is not the same. In fact, sorting twice really does sort a list twice. If you have a large amount of elements, you will notice that. Having a sortedWith(...) specifies one comparator (no matter how many "thenBy" clauses you use - it will become one Comparator) sorts only once.
    So, always use the one comparator approach. :-)

  • Custom User Avatar

    yeah nice catch! youre right, the third sortedByDescending is unnecesary.
    but I belive sortedWith plus thenBy have same mechanism with sorting twice.
    aside from that, folding or not, 96 or 'a' its same lah, not hiding any fact :D
    cheers 🍻

  • Custom User Avatar

    You are unnecessarily sorting three(!) times - your last sortedByDescending is done even twice identically. But the main problem is that sorting by two criteria should never be done by sorting twice.
    Folding with a start value of length is just disguising the otherwise pretty simple sum of the elements plus the length.
    96 is a "magic constant" and which hides the fact you're actually subtracting 'a' and making it 1-based.
    This is not to be considered a best practice at all... :-)