Ad
  • Default User Avatar

    This one blows my mind

    I've searched all over the place to find mathematical proof of how this dead-simple algorithm works, but it's seemingly magic lol

    I had come up with a pen-and-paper way to construct the partitions by laying them out in a left-aligned triangle and summing up offset diagonals to produce new terms, but couldn't figure out how to put that to code

    This algorithm seems to resemble that triangle idea, but instead only needs a single row of numbers, and it doesn't seem to even remotely relate to partitions, yet it works lol

  • Default User Avatar

    I should really have named "digits" here as "digit_count" because it simply counts the number of times each digit appears in x. This way of doing it only requires a regular fixed-size array of 10 (one for each digit 0 to 9).

  • Default User Avatar

    (Programming Language: C)
    For some reason the straightforward approach did not pass the tests on my end, even though the top answers are just that. I had to optimise further for accuracy and speed lol