Pluckerpluck

joined 11 months ago
[–] Pluckerpluck@programming.dev 5 points 11 months ago

If you didn’t happen to do string replacements it wasn’t so bad.

Yeah. I was using regex to find the numbers as a quick implementation before realizing that floor. Just switched it to use a positive lookahead to solve that issue.

Day 3 was one of those challenges that if you thought of a good method quickly it wasn't too bad. Ended up compiling strings and using regex again. Worked really well actually.

[–] Pluckerpluck@programming.dev 3 points 11 months ago

Except the point of this post is that a different sort with worse Big O could be faster with a small dataset.

The fact that you're sorting those 64 ints billions of times simply doesn't matter. The "slower" sort is still faster in practice.

That's why it's important to realize that Big O notation can be useless for small datasets. Because it can actually just be lying to you.

It's actually mathematical. Take any equation:

y = x^2 + x

For large x the squared term dominates. The linear may as well not exists. It's O(x^2). But when x is below 1? Well suddenly that linear term is the more important one! Below 1 it's actually O(x) in practice.