Futoshiki
GitHubFutoshiki is a Scala program for generating Futoshiki solvers written in Prolog.
Example
First, generate the solver:
import dev.scown.futoshiki.{Futoshiki, Constraints}
import dev.scown.futoshiki.prolog.CodeGenerator
// create an instance of the puzzle
val puzzle = Futoshiki(
Map((1,1) -> 4),
Constraints(List(
((1,2), (1,3)),
((1,3), (1,4)),
((2,1), (1,1)),
((2,4), (2,5)),
((3,1), (2,1)),
((3,1), (3,2)),
((3,2), (3,3)),
((3,2), (4,2)),
((4,3), (3,3)),
((4,3), (4,2)),
((5,2), (4,2)),
((4,5), (5,5)),
((5,4), (5,3)),
((5,5), (5,4))
))
)
// write the prolog solver to a PrintStream
CodeGenerator(puzzle).writeProlog(System.out)
Then import it into your Prolog REPL:
?- ['my-solver'].
true.
futoshiki(V_1_1,
V_1_2,
V_1_3,
V_1_4,
V_1_5,
V_2_1,
V_2_2,
V_2_3,
V_2_4,
V_2_5,
V_3_1,
V_3_2,
V_3_3,
V_3_4,
V_3_5,
V_4_1,
V_4_2,
V_4_3,
V_4_4,
V_4_5,
V_5_1,
V_5_2,
V_5_3,
V_5_4,
V_5_5).
Prolog will then find an assignment that satisfies the constraints of the puzzle.
Technical Details
Futoshiki is implemented in Scala 2.11.
The solvers have been tested in SWI-Prolog version 7.4.2. However, they don’t use any exotic features and should be compatible with any Prolog implementation.