Fast pentomino puzzle solver ported from Forth to Python
1–10 of 16 posts
Re: Fast pentomino puzzle solver ported from Forth to Python
#2If you haven't seen Knuth's Dancing Links implementation of Algorithm X, I highly recommend it. It's based on the observation that updating a doubly-linked list in-place preserves enough information to make backtracking easy.
Re: Fast pentomino puzzle solver ported from Forth to Python
#3Re: Fast pentomino puzzle solver ported from Forth to Python
#4https://nbviewer.jupyter.org/gist/denfromufa/9a5e1fdeaf611dc...
Re: Fast pentomino puzzle solver ported from Forth to Python
#5Re: Fast pentomino puzzle solver ported from Forth to Python
#6This is a specific example of an Exact cover problem: https://en.wikipedia.org/wiki/Exact_cover If you haven't seen Knuth's Dancing Links implementation of Algorithm X, I highly recommend it. It's based on the observation that updating a doubly-linked list in-place preserves enough information to make backtracking easy.
Re: Fast pentomino puzzle solver ported from Forth to Python
#7This is a specific example of an Exact cover problem: https://en.wikipedia.org/wiki/Exact_cover If you haven't seen Knuth's Dancing Links implementation of Algorithm X, I highly recommend it. It's based on the observation that updating a doubly-linked list in-place preserves enough information to make backtracking easy.
UPDATE: think I may see it, sounds like in terms of partitions an exact cover is a subset of a set's partition.
Re: Fast pentomino puzzle solver ported from Forth to Python
#8Pedantic note: Special methods aren't looked up in __dict__, they're members of the C struct describing the type. "board[pos]" will look up the type of board, then call the tp_getitem function pointer in that struct. That can be a bit surprising to people:
class A:
def __getitem__(self, key):
print("A.__getitem__({})".format(key))
def foo(self, x):
print("A.foo({})".format(x))
a = A()
a["special"]
a.foo("ordinary")
a.__getitem__ = lambda key: print("Overriden __getitem__({})".format(key))
a.foo = lambda x: print("Overriden foo({})".format(x))
a["special"]
a.foo("ordinary")
Outputs: A.__getitem__(special)
A.foo(ordinary)
A.__getitem__(special)
Overriden foo(ordinary)Re: Fast pentomino puzzle solver ported from Forth to Python
#9This is a specific example of an Exact cover problem: https://en.wikipedia.org/wiki/Exact_cover If you haven't seen Knuth's Dancing Links implementation of Algorithm X, I highly recommend it. It's based on the observation that updating a doubly-linked list in-place preserves enough information to make backtracking easy.
It includes a sudoku (also exact cover) and pentonimo solver.
Re: Fast pentomino puzzle solver ported from Forth to Python
#10I wonder what a solution in prolog would look like. That language always seemed geared to solve riddles. You describe the solution and it can tell you how to arrive there.