« first day (5170 days earlier)   

02:50
@Aran-Fey It's related to the knapsack problem family. en.wikipedia.org/wiki/Knapsack_problem That's usually given in terms of addition, but multiplication & addition are isomorphic, via logarithms. ;)
Generally, these problems are NP-complete, like the Travelling Salesman Problem. So it can get ugly, unless the number of items is small, or the system has constraints that limit the exponential growth of the solution tree.
If you only have two sets to choose from, it's pretty easy. If you have a 100 sets, it might take some time...
If you have a smallish number of sets, containing a smallish set of "nice" numbers, there are probably heuristic algorithms that usually give fairly good solutions close to the optimum, most of the time, but which can fail when fed nasty data.
 
4 hours later…
06:53
Oof. Thankfully my sets are rather small and there probably won't be many of them (up to 3 maybe, realistically), but... this is for a __str__ method :/ I guess I'll settle for a fast approximation
 
2 hours later…
08:29
I'm really curious as to how one gets into this optimisation problem for a .__str__ method. How can it be anything other than deterministic?
09:07
Deterministic does not mean it cannot be optimised, on the contrary
I have a quantity of some kind (like 3500m/s) and need to find the most suitable unit for it (km/s in this case, probably)
Well if it's really the metric system you can go while quantity > 1000: quantity /= 1000; unit = next(unit). I did something similar in a function called "human_time_ago"
def human_time_ago(seconds_ago: float) -> str:
    """Return time difference as human-readable string"""
    periods = (
        ("year", 60 * 60 * 24 * 365),
        ("month", 60 * 60 * 24 * 30),
        ("week", 60 * 60 * 24 * 7),
        ("day", 60 * 60 * 24),
        ("hour", 60 * 60),
        ("minute", 60),
    )

    for period, seconds_each in periods:
        if seconds_ago >= seconds_each:
            how_many = int(seconds_ago / seconds_each)
            return f"{how_many} {period}{'s' if how_many >= 2 else ''} ago"
@matszwecja Sorry, I wasn't clear. In my mind .__str__ is literally just shoving a class description into a string, isn't it? The class itself might encapsulate an optimisation problem but how do you get from <class SomeSolver ...> to needing to solve the problem itself in there?
But from Aran's method, I see it now. I had endless mental arguments with myself on the MRP I'm building and in the end I just left it to the user to configure this stuff. In my example making sweets, the system I used to work with reported sugar in tonnes so in the product spec everyone was used to 0.0000005 or whatever (I didn't count the zeros) being reported by their system
So in theory for this unit app, can you not just have it as some kind of config param for the user as to what units they would want to display?
IOW by being friendly and trying to find the best denomination of the unit, I as a user would be hamstrung trying to compare my output from the existing system data that I'm trying to upgrade, and I'd have to reverse the calculation all the time to make sure my units matched
09:34
I have a library, so a config doesn't really make sense. I want a sensible default implementation, in part because it's a tricky problem and most people won't bother writing the code for it
I meant a config in this sense
Then again, I suppose you'll be in a chicken and egg situation since the units they want to be displayed are the very units they've just created in your library :/
A library with configuration options just doesn't seem like a good idea. What if your code isn't the only code that wants to configure it?
I'm not entirely sure I can envisage that situation. The options are purely for display so only for humans, which __str__ is
10:21
Honestly, I don't feel like it's a good idea. The most suitable unit isn't decided by it's magnitude (mostly), but by the context. If something goes terribly wrong when calculating speed of my car, I'd rather see 324000 km/h than 90 km/s. One is obviously wrong at the first glance, while the other takes it look like a very sensible speed until you notice the unit.
I think you should describe your problem again more clearly and indicate why you need to solve a combinatorics problem
@matszwecja The newest Vauxhall Astra really doubled down on the "astral" angle, huh?
11:17
<adds this to the "dumb" list for Jupyter>. I can't test right now but everything I'm reading seems to suggest the multiprocessed code needs to be in a different notebook because reasons
 
5 hours later…
16:07
@NordineLotfi you're aware that getting on the AoC leaderboard using AI tooling is forbidden, right?
@Aran-Fey can you use a canonical unit (m/s) and then pre-generate (probably caching on-demand calculations) of all possible combinations? So basically you'll know ahead of time that "m/s" is 1, and "km/h" is 3.6 and "km/s" is 1000, and then you only have a 1d binary search.
I assume you'll want to dynamically support this for all sorts of units, so anything with a*b/c kind of dimensions will need an even larger space.... so perhaps storing these is not such a great idea after all.
By the way, does your library handle "ohm mm^2/m" units? :D
16:26
What's on your mind?, a Meta Stack Exchange invitation to discussion
3
Oh no, employee spamming chatrooms! :P
I'll pin that, Slate, in case someone wants to look
I've always like the bird, by the way
s/like/liked/
16:43
tl;dr she's especially interested in the views of people who don't normally frequent meta, with big-picture thoughts about the future of the platform
@AndrasDeak--СлаваУкраїні hmm?
what do you mean
if I used "AI tooling" I wouldn't be doing them in 1-2min though
the people doing them in 10-15 seconds are definitely doing this however
last year I was 59th but I took the time this year to train with project euler and past aoc years
@AndrasDeak--СлаваУкраїні and? 30 seconds is doable
32 seconds to read and type a solution?
you barely need 12 words min to solve some of the puzzle
16:54
I guess science has gone a long way, because in 2022 day 11 needed 6 years to solve for part 1
if you did a lot of competitive programming, you aren't supposed to read the whole thing. once you do this enough time, you just build an intuition
For some reason in 2023 and especially 2024 solution times plummeted. Even for day 1.
day 1 is very easy though
I admit later days are much much harder
to be fair I've also factored in my impression of your personality
last one I did, forgot which day, I think it took me like 7 min? or smth like that
@AndrasDeak--СлаваУкраїні tbf you don't really know me :)
I act differently on SO/SE vs other places
16:56
hence "impression" :P
that's fair yeah
it's too bad I never could make a better impression haha
well, I guess that's fine either way
@AndrasDeak--СлаваУкраїні Yeah, I'm worried about the same thing. I've got a lot of prefixes to work with. Maybe I could exclude them from the cached data somehow, but I haven't thought it through yet
I've pretty much decided to let it be for now. I just wanted to get the project into a publishable state, since it's been sitting around 99%-finished for a few months
@AndrasDeak--СлаваУкраїні The library can handle it, but my brain power not insufficient for me to include a definition of Ohms. Teaching the type checker all of the different formulas that are equivalent to electric resistance is beyond me :D
 
4 hours later…
21:06
Kinda sad that a lot of math mistakenly gets flagged as incorrect. For example meter * meter / meter doesn't get recognized as a valid Distance. Any chance we'll get a TypeVarMultiSet at some point? :(
Not quite close enough, I'm afraid

« first day (5170 days earlier)