Quick question: Do you think it’s cheating to have...
# advent-of-code
m
Quick question: Do you think it’s cheating to have a large number of utility functions prepared? I think that in a way it is. Difficult to say! To me AoC is about finding a good solution from scratch using only what comes with the language, but then again templates are probably fine. Not sure where to draw a line …
p
No not at all. In the end the stdlib is also just a library, so use the tools you have.
But yeah if you want a real challenge, exclude the stdlib ;-)
m
Sure, I know. And what’s included with the language varies a lot between languages.
One way of defining it could be to say that any library is fine which takes you to the level of the most powerful languages (with their standard libraries).
s
I wouldn't say that's cheating. I think part of the beauty of Advent of Code is that you can use any tool or method of solving the problem, I mean some geniuses just solve some issues immediately with math and so on
e
in some sense, I'm ok with using stdlib and other libraries I feel like I could theoretically write myself if I had time
but everybody can have their own approach to AoC; there were definitely solutions yesterday using Z3 theorem prover, which is likely not something you can write yourself even if you wanted to 😉
Eric has said that his goal is for people to learn, so as long as that's happening, you're good
p
I honestly don't care at all. If someone would retrain a ml model to get the job done, that's fantastic. Use what you like :)
m
Here’s an example: For some challenges I wrote a function that creates permutations of a list. Here it is:
Copy code
fun <V> List<V>.permutations(): List<List<V>> {
    val result: MutableList<List<V>> = mutableListOf()

    fun generate(k: Int, list: List<V>) {
        // If only 1 element, just output the array
        if (k == 1) {
            result.add(list.toList())
            return
        }
        for (i in 0 until k) {
            generate(k - 1, list)
            swap(list, if (k % 2 == 0) i else 0, k - 1)
        }
    }

    generate(count(), toList())
    return result
}
If I used that in a challenge, I feel like I would have to include (copy) it in the code presented as the solution. It feels kind of wrong to just import it and then pretend that my solution is 25 lines shorter 😉
m
I also have a permutations function in my utils file, that I created in previous years. I don't see that as cheating, after all I wrote it myself, so I don't see it any different as pre-writing input reading as most people do. Today I used a pre-written
Point
class with a
getAdjacentSides()
method to get adjacent points for the basin flood-fill. I would never use an external library, but anticipating what can be useful is part of the fun for me.
e
@Michael Böiers with a bit of thought, permutations can be generated sequentially and non-recursively: https://pl.kotl.in/zk2yB8kXo
e
In competitive programming this in not consider cheating. Contests usually explicitly allow both personal prewritten code and copying code from internet if that code was available before the start of the contest. Exceptions are rare. Those are usually contests that were formerly on-site and had recently moved online due to pandemic. Copying someone else's solution to the problem, though, is universally considered cheating.