def hanoi(): from hornet import Database, pyfunc, _, greater, let, cut from hornet.symbols import play_hanoi, move, M, N, From, With, To @pyfunc def show_move(N, From, To, With): towers[To()].push(towers[From()].pop()) db = Database() db.tell( play_hanoi(N, From, To, With) << greater(N, 0) & move(N, From, To, With), move(1, From, To, _)[show_move] << cut, move(N, From, To, With) << let(M, N - 1) & move(M, From, With, To) & move(1, From, To, _) & move(M, With, To, From), ) for subst in db.ask(play_hanoi(6, 0, 1, 2)): print('Yes.') break else: print('No.')
def test_resolver(): from pprint import pprint from hornet import Database from hornet.symbols import _, f, g, h, a, b, c, X, Y, Z db = Database() db.tell( a, f(a, b, c), f(a, a, a), f(c, b, a), f(X, Y, Z) << g(X, a) & h(Y, b) & c, g(X, X, Y), h(X) << g(X, a, _) | g(X, b, _), ) pprint(db) for subst in db.ask(g(a, Z, Z)): pprint(subst) for subst in db.ask(g([a, b | c], Z, Z)): pprint(subst) for subst in db.ask(f(X, Y, Z)): pprint(subst) for subst in db.ask(h(X)): pprint(subst) for subst in db.ask(~g(a, b, Y)): print(subst)