this post was submitted on 02 Feb 2024
22 points (100.0% liked)
Programming
17655 readers
189 users here now
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Rules
- Follow the programming.dev instance rules
- Keep content related to programming in some way
- If you're posting long videos try to add in some form of tldr for those who don't want to watch videos
Wormhole
Follow the wormhole through a path of communities !webdev@programming.dev
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
If I understand the problem correctly, this is the solution:
solution
a = 2299200278b = 2929959606
c = 2585800174
d = 3584110397
I solved it with Z3. Took less than a second of computer time, and about an hour of my time -- mostly spent trying to remember how the heck to use Z3 and then a little time debugging my initial program.
Yep, that's correct. I never heard about Z3 and I did it by reverting all the operation. It takes couple of seconds of computer time to solve my way but it took me closer to 7h to figure it out. 1h is impressive.
There are actually two possible solutions because some bits are lost when generating numbers. Can Z3 account for lost bits? Did it come up with just one solution?
It gave me just one solution the way I asked for it. With additional constraints added to exclude the original solution, it also gives me a second solution -- but the solution it produces is peculiar to my implementation and does not match your implementation. If you implemented exactly how the bits are supposed to end up in the result, you could probably find any other solutions that exist correctly, but I just did it in a quick and dirty way.
This is (with a little clean up) what my code looked like:
solver code
If you're not familiar with SMT solvers, they are a useful tool to have in your toolbox. Here are some links that may be of interest:
Edit: Trying to fix formatting differences between kbin and lemmy
Edit 2: Spoiler tags and code blocks don't seem to play well together. I've got it mostly working on Lemmy (where I'm guessing most people will see the comment), but I don't think I can fix it on kbin.
I think that's the issue, in the second possible solution one of the parameters is negative :)
This looks great, I didn't even know it's possible to solve it this way. I'm glad someone dedicated some time to it. Let's see if anyone will try solving it in other way.