This is a short Perl program built to solve Jane Street's January 2017 puzzle, Hex-agony #2.
The script makes a number of assumptions about the solution, which seemed reasonable after fiddling with the problem by hand. These assumptions greatly reduced the search space, and so you may observe that the script finds the correct solution in ~1 second on ageing hardware.
- There is a green 130,321 in the middle column
- The red 169 has a blue 169 visible to it (implying that there are two black 13s whose product is 169)
The Hex-agony puzzle is mapped to coordinates such that the bottom hex has row index 8:
- Green 130,321
- Is in the middle column
- Black 19s
- Can see at least 19 "empty" hexes (which we later assume are red after solving the puzzle)
- Can see green 130,321
- Not visible to green 1
- Are four of these
- Blue 169
- Visible to red 169
- Not visible to green 1
- Not obstructing any of the black 19s from seeing >= 19 empty spaces
- Green 169
- Visible to blue 169
- Not obstructing any of the black 19s from seeing >= 19 empty spaces
- Black 13s
- Not visible to green 130,321
- Visible to green 169
- Can see >= 13 empty spaces
- Not obstructing any of the black 19s from seeing >= 19 empty spaces
Solving these constraints results in this output from the Perl script:
And a bit of manual number crunching gives the final solution: