[Math] Solving Integer Linear Problem during hangover

I bought 6 cans of beer. 5 -- somewhat more expensive. One can -- somewhat cheaper. Store clerk asked 244 UAH. What price of each can?

Such problem can be solver easily using SMT solver (including Z3), but many other tools exists. Let's try Wolfram Mathematica.

We've got a system of equation:

3 possible solutions:

In[]:= Solve[5*x + y == 244 && x > 0 && y > 0 && Abs[x - y] < 20 && x > y, {x, y}, Integers]
Out[]= {{x -> 41, y -> 39}, {x -> 42, y -> 34}, {x -> 43, y -> 29}}

ILP because we work with integer prices. Kopecks are not used in Ukraine anymore. Even if used, both variables can reflect price in kopecks, and constants as well.

More info about Mathematica's Solve[] function.

(the post first published at 20231023.)


List of my other blog posts.

Subscribe to my news feed

Yes, I know about these lousy Disqus ads. Please use adblocker. I would consider to subscribe to 'pro' version of Disqus if the signal/noise ratio in comments would be good enough.