Ad
  • Default User Avatar

    Notes:

    • Not written fresh; combines code from a couple of the other solutions; cursory testing suggests it's faster than them.
    • Relies perhaps too much on lambdas.
    • Uses the fact that tuples can be ordered based on their fields, with the first field having precedance. Some quick testing showed this had very noticible impact on performance; presumably this has to do with being able to skip unboxing the values.
      I first saw this in rhr's solution.
    • Swaps the definition order of the fields in PickedPeaks,
      which means no final swapping of the indexes and values is needed before passing to PickedPeaks. This doesn't seem to impact performance much, if at all, but it makes for cleaner code. Because record syntax is used in all the tests it still works exactly the same.
    • Being pointfree seems to represent a small speedup
  • Default User Avatar

    If you imagine a set as a bag of things, then a permutation is one possible result of pulling random things out the bag one at a time and putting them in a row until the bag is empty. What you describe are usually called the n-tuples of a set (specifically ones where n is equal the size of the set). There's some more info here: https://en.wikipedia.org/wiki/Permutation#Permutations_with_repetition

  • Default User Avatar

    It's not, it just converts it from a character to an integer; it seems that cubing a sequence before summing it doesn't change whether the sum will be divisible by 2! Quite a nice observation, and requires less work.

  • Default User Avatar

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