This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/packages/pyswip/examples/coins/coins.py

23 lines
654 B
Python
Raw Normal View History

2010-06-01 00:33:32 +01:00
# -*- 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()