port of PYSWIP package.

This commit is contained in:
Vítor Santos Costa
2010-06-01 00:33:32 +01:00
parent 0645040602
commit e94104306c
27 changed files with 2502 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# 100 coins must sum to $5.00
from pyswip.prolog import Prolog
def main():
prolog = Prolog()
prolog.consult("coins.pl")
count = int(raw_input("How many coins (default: 100)? ") or 100)
total = int(raw_input("What should be the total (default: 500)? ") or 500)
for i, soln in enumerate(prolog.query("coins(S, %d, %d)." % (count,total))):
# [1,5,10,50,100]
S = zip(soln["S"], [1, 5, 10, 50, 100])
print i,
for c, v in S:
print "%dx%d" % (c,v),
print
list(prolog.query("coins(S, %d, %d)." % (count,total)))
if __name__ == "__main__":
main()