Re:Solving 100 Bushels Using Matrix Factorization
by Joker_vD on Wednesday October 02, 2024 @09:16AM
(#41720280)
Just want to note that "brute force search" is called "brute force" instead of e.g. "search with heuristics" for a reason. Of course you can trim down the search space if you think about the properties of the problem but the whole point of using a brute force approach is to literally allow yourself to not think about the problem.
Re:Solving 100 Bushels Using Matrix Factorization
by Etherlord87 on Wednesday October 02, 2024 @12:01PM
(#41722005)
Whatever you do, you need to find some reasonable balance. You need to reason on what are the minimum possible values for the variables and what are the maximums. In my example the reasoning effort was minimal, much less than figuring the `c` is even or the `w` is divisible by 5.
Otherwise OP made an error in using range(0, 100) instead of range(0, 101), but even here you could pedantically point out "how do you know the numbers can't be negative or over 100? You're not supposed to think too much when brute-forcing!" - well you have to do some minimal thinking always :P
Also notice my code is actually simpler.
Re:Solving 100 Bushels Using Matrix Factorization
by lupire on Wednesday October 02, 2024 @06:52PM
(#41725668)
Your code also has a bug, which would affect the result in some variations of the problem with different parameters, but fortunately does not affect this specific version. You also used 100.
Re:Solving 100 Bushels Using Matrix Factorization
by Etherlord87 on Saturday October 05, 2024 @03:09PM
(#41752146)
The code wasn't written for other parameters, so it doesn't have a bug.
Re:Solving 100 Bushels Using Matrix Factorization
by satisfice on Wednesday October 02, 2024 @01:43PM
(#41723141)
what I was going for is simplicity. I wanted code that mapped to the plain conceptual structure of the problem. As soon as you optimize it you begin to obfuscate the code.
Of course, with a bigger problem we will have to optimize.
There's no need for the 3rd loop! Once you have candidates for m and w, there's only one possible c satisfying the requirements. And so you also don't need to check for their sum being 100.