Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
yuce committed Oct 26, 2024
1 parent 4441ad7 commit e243432
Show file tree
Hide file tree
Showing 26 changed files with 517 additions and 234 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ See the [Change Log](https://pyswip.org/change-log.html).

If you have SWI-Prolog installed, it's just:
```
pip install pyswip
pip install -U pyswip
```

See [Get Started](https://pyswip.readthedocs.io/en/latest/get_started.html) for detailed instructions.
Expand Down
14 changes: 14 additions & 0 deletions docs/source/api/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,17 @@ Sudoku

.. automodule:: pyswip.examples.sudoku
:members:

Hanoi
^^^^^

.. automodule:: pyswip.examples.hanoi
:members:


Coins
^^^^^

.. automodule:: pyswip.examples.coins
:members:

2 changes: 1 addition & 1 deletion docs/source/get_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ PySwip is available to install from `Python Package Index <https://pypi.org/proj

You can install PySwip using::

pip install pyswip
pip install -U pyswip

You will need to have SWI-Prolog installed on your system.
See :ref:`install_swi_prolog`.
Expand Down
4 changes: 2 additions & 2 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ This directory contains examples for PySwip.

The ones marked with (clp) requires `clp` library of SWI-Prolog.

* (clp) `coins/`
* (clp) `coins/` : Moved to `pyswip.examples.coins` package
* (clp) `draughts/`
* `hanoi/` : Towers of Hanoi
* `hanoi/` : Moved to `pyswip.examples.sudoku` package
* (clp) `sendmoremoney/` : If, SEND * MORE = MONEY, what is S, E, N, D, M, O, R, Y?
* (clp) `sudoku/` : Moved to `pyswip.examples.sudoku` package
* `create_term.py` : Shows creating a Prolog term
Expand Down
8 changes: 4 additions & 4 deletions examples/coins/coins.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

:- use_module(library('bounds')).

coins(S, Count, Total) :-
coins(Count, Total, Solution) :-
% A=1, B=5, C=10, D=50, E=100
S = [A, B, C, D, E],
Solution = [A, B, C, D, E],

Av is 1,
Bv is 5,
Expand All @@ -31,8 +31,8 @@
VD #= D*Dv,
VE #= E*Ev,

sum(S, #=, Count),
sum(Solution, #=, Count),
VA + VB + VC + VD + VE #= Total,

label(S).
label(Solution).

41 changes: 0 additions & 41 deletions examples/coins/coins.py

This file was deleted.

2 changes: 1 addition & 1 deletion examples/coins/coins_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def main():
total = int(input("What should be the total (default: 500)? ") or 500)
coins = Functor("coins", 3)
S = Variable()
q = Query(coins(S, count, total))
q = Query(coins(count, total, S))
i = 0
while q.nextSolution():
## [1,5,10,50,100]
Expand Down
2 changes: 1 addition & 1 deletion examples/create_term.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# SOFTWARE.

from pyswip.core import *
from pyswip.prolog import Prolog
from pyswip import Prolog


def main():
Expand Down
2 changes: 1 addition & 1 deletion examples/draughts/puzzle1.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# are four guards watching each wall. How can they be rearranged such
# that there are five watching each wall?"

from pyswip.prolog import Prolog
from pyswip import Prolog


def main():
Expand Down
87 changes: 0 additions & 87 deletions examples/hanoi/hanoi.py

This file was deleted.

40 changes: 0 additions & 40 deletions examples/hanoi/hanoi_simple.py

This file was deleted.

4 changes: 2 additions & 2 deletions examples/knowledgebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from pyswip import *
from pyswip import Prolog, Functor, Variable, Query, newModule, call


def main():
_ = Prolog()
_ = Prolog() # not strictly required, but helps to silence the linter

assertz = Functor("assertz")
parent = Functor("parent", 2)
Expand Down
7 changes: 2 additions & 5 deletions examples/register_foreign_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@
from pyswip.easy import registerForeign


def hello(t):
print("Hello,", t)


hello.arity = 1
def hello(who):
print("Hello,", who)


def main():
Expand Down
38 changes: 38 additions & 0 deletions src/pyswip/examples/coins.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

% Coins -- 2007 by Yuce Tekol <[email protected]>

:- use_module(library('bounds')).

coins(Count, Total, Solution) :-
% A=1, B=5, C=10, D=50, E=100
Solution = [A, B, C, D, E],

Av is 1,
Bv is 5,
Cv is 10,
Dv is 50,
Ev is 100,

Aup is Total // Av,
Bup is Total // Bv,
Cup is Total // Cv,
Dup is Total // Dv,
Eup is Total // Ev,

A in 0..Aup,
B in 0..Bup,
C in 0..Cup,
D in 0..Dup,
E in 0..Eup,

VA #= A*Av,
VB #= B*Bv,
VC #= C*Cv,
VD #= D*Dv,
VE #= E*Ev,

sum(Solution, #=, Count),
VA + VB + VC + VD + VE #= Total,

label(Solution).

Loading

0 comments on commit e243432

Please sign in to comment.