Live data from Hacker News

From hours to 360ms: over-engineering a puzzle solution

blog.danielh.cc

11–20 of 39 posts

Re: From hours to 360ms: over-engineering a puzzle solution

#11
post #6

If anything, what a testament of the massive failure Z3 is.

Can you say more about this? On the face of it this comment seems ridiculous to me. Z3 is fabulously successful in other domains. Perhaps the problem fit is not there, or the problem encoding chosen was not appropriate.

(Way) worse than exhaustive brute force search ... you don't really have to say much more.

I think it's the first time I see such thing in the wild.

Re: From hours to 360ms: over-engineering a puzzle solution

#12
post #10
post #8

Sigh. My friend did this problem on pen and paper and made me feel stupid. Their solution was so wildly clever! It relied on the observation that the sum of the rows of the sudoku board (given the digits in use) is a known fixed value, and went from there (I'll leave the rest as an exercise to the reader to avoid spoilers).

This isn't exactly a sudoku board, because they allow for 0.

While it's not a true sudoku board, that invariant still holds. Whichever set of digits you end up using (it'll be the same 9 for rows, columns, and blocks) the sum will be same for all of them. It's also unique to the set of 9 numbers you end up using to solve the puzzle.

If you use 1-9, sum is 45. For anything else, it's 45 - (the unused number).

Re: From hours to 360ms: over-engineering a puzzle solution

#13
post #10
post #8

Sigh. My friend did this problem on pen and paper and made me feel stupid. Their solution was so wildly clever! It relied on the observation that the sum of the rows of the sudoku board (given the digits in use) is a known fixed value, and went from there (I'll leave the rest as an exercise to the reader to avoid spoilers).

This isn't exactly a sudoku board, because they allow for 0.

Yep, I'm aware, hence the given digits part. The whole board is still drawn from 9 digits, it's just that precisely which 9 digits is unknown.

Re: From hours to 360ms: over-engineering a puzzle solution

#14

If anything, what a testament of the massive failure Z3 is.

Unless I missed it, their Z3 solution wasn't even presented. So we can't comment on how good or bad Z3 is without seeing how good or bad their Z3 attempt was.

That is true, indeed.

It could be that the author is just massively unskilled at writing Z3 code.

Re: From hours to 360ms: over-engineering a puzzle solution

#17
Since we're over-engineering here, one more optimization is to skip all potential GCDs that are divisible by 2 or 5.

Suppose the GCD was divisible by 2, then all rows would be even. Since the last digit of an even integer is in {0,2,4,6,8} and we need 9 unique numbers in the final column, we know that 4 or 5 of the row numbers must be odd. So the GCD can't be even.

Similarly, the GCD can't be divisible by 5. If it were, all rows numbers would need a 0 or 5 in the final digit.

Re: From hours to 360ms: over-engineering a puzzle solution

#18
post #8

Sigh. My friend did this problem on pen and paper and made me feel stupid. Their solution was so wildly clever! It relied on the observation that the sum of the rows of the sudoku board (given the digits in use) is a known fixed value, and went from there (I'll leave the rest as an exercise to the reader to avoid spoilers).

The Jane Street page explains the (a?) number theory approach.

Re: From hours to 360ms: over-engineering a puzzle solution

#19
post #17

Since we're over-engineering here, one more optimization is to skip all potential GCDs that are divisible by 2 or 5. Suppose the GCD was divisible by 2, then all rows would be even. Since the last digit of an even integer is in {0,2,4,6,8} and we need 9 unique numbers in the final column, we know that 4 or 5 of the row numbers must be odd. So the GCD can't be even. Similarly, the GCD can't be divisible by 5. If it we…

We know that the GCD is divisible by 9 because the sum of the digits for every row is 45.

Re: From hours to 360ms: over-engineering a puzzle solution

#20
post #17

Since we're over-engineering here, one more optimization is to skip all potential GCDs that are divisible by 2 or 5. Suppose the GCD was divisible by 2, then all rows would be even. Since the last digit of an even integer is in {0,2,4,6,8} and we need 9 unique numbers in the final column, we know that 4 or 5 of the row numbers must be odd. So the GCD can't be even. Similarly, the GCD can't be divisible by 5. If it we…

We know that the GCD is divisible by 9 because the sum of the digits for every row is 45.

Not necessarily. The sum of the digits ranges from 36-45, there are 10 possible digits of which 9 will be used. If, say, 5 were the unused number then it would not be divisible by 9.
Post reply on HN