Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Vít Novotný
pb016-priklady
Commits
36a8866b
Commit
36a8866b
authored
Jan 25, 2017
by
Vít Novotný
Browse files
added example 6.2_11
parent
001f2184
Changes
4
Hide whitespace changes
Inline
Side-by-side
6.2_11.pl
0 → 100644
View file @
36a8866b
% nacteni:
/*
['6.2_11.pl'].
*/
:-
retractall
(
start
/
0
).
:-
use_module
(
library
(
clpfd
)).
% clpq , clpr
moremoney
([
S
,
E
,
N
,
D
,
M
,
O
,
R
,
Y
],
Type
)
:-
[
S
,
E
,
N
,
D
,
M
,
O
,
R
,
Y
]
ins
0
..
9
,
S
#>
0
,
M
#>
0
,
all_different
([
S
,
E
,
N
,
D
,
M
,
O
,
R
,
Y
]),
sum
(
S
,
E
,
N
,
D
,
M
,
O
,
R
,
Y
),
labeling
(
Type
,
[
S
,
E
,
N
,
D
,
M
,
O
,
R
,
Y
]).
sum
(
S
,
E
,
N
,
D
,
M
,
O
,
R
,
Y
):-
1000
*
S
+
100
*
E
+
10
*
N
+
D
+
1000
*
M
+
100
*
O
+
10
*
R
+
E
#=
10000
*
M
+
1000
*
O
+
100
*
N
+
10
*
E
+
Y
.
:-
dynamic
start
/
0
.
start
:-
write
(
'CLP - Algebrogram'
),
nl
,
nl
,
write
(
' S E N D'
),
nl
,
write
(
'+ M O R E'
),
nl
,
write
(
'----------'
),
nl
,
write
(
'M O N E Y'
),
nl
,
nl
,
write
(
'Vysledek dotazu "moremoney([S,E,N,D,M,O,R,Y],[])":'
),
nl
,
moremoney
([
S
,
E
,
N
,
D
,
M
,
O
,
R
,
Y
],[]),
write
(
' S = '
),
write
(
S
),
write
(
', E = '
),
write
(
E
),
write
(
', N = '
),
write
(
N
),
write
(
', D = '
),
write
(
D
),
write
(
', M = '
),
write
(
M
),
write
(
', O = '
),
write
(
O
),
write
(
', R = '
),
write
(
R
),
write
(
', Y = '
),
write
(
Y
),
nl
.
?-
start
.
6.2_11.py
0 → 100644
View file @
36a8866b
#!/usr/bin/env python
# encoding=utf-8 (pep 0263)
# je zapotrebi nainstaloval balicek python-constraint
from
constraint
import
Problem
,
AllDifferentConstraint
problem
=
Problem
()
domain
=
range
(
10
)
variables
=
(
"S"
,
"E"
,
"N"
,
"D"
,
"M"
,
"O"
,
"R"
,
"Y"
)
for
name
in
variables
:
problem
.
addVariable
(
name
,
domain
)
problem
.
addConstraint
(
lambda
s
:
s
>
0
,
(
"S"
))
problem
.
addConstraint
(
lambda
m
:
m
>
0
,
(
"M"
))
problem
.
addConstraint
(
AllDifferentConstraint
())
problem
.
addConstraint
(
lambda
s
,
e
,
n
,
d
,
m
,
o
,
r
,
y
:
\
1000
*
s
+
100
*
e
+
10
*
n
+
d
+
1000
*
m
+
100
*
o
+
10
*
r
+
e
==
10000
*
m
+
1000
*
o
+
100
*
n
+
10
*
e
+
y
,
variables
)
# demonstracni vypis
if
__name__
==
"__main__"
:
print
(
"CLP - Algebrogram
\n
"
)
print
(
" S E N D"
)
print
(
"+ M O R E"
)
print
(
"---------"
)
print
(
"M O N E Y
\n
"
)
print
(
"Vysledek volani problem.getSolutions():"
)
solution
=
problem
.
getSolutions
()[
0
]
print
(
" S = %s, E = %s, N = %s, D = %s, M = %s, O = %s, R = %s, Y = %s"
%
\
tuple
((
solution
[
x
]
for
x
in
variables
)))
6.2_11.py.out
0 → 100644
View file @
36a8866b
CLP - Algebrogram
S E N D
+ M O R E
---------
M O N E Y
Vysledek volani problem.getSolutions():
S = 9, E = 5, N = 6, D = 7, M = 1, O = 0, R = 8, Y = 2
Makefile
View file @
36a8866b
...
...
@@ -3,7 +3,7 @@
IGNORED_PYLINT_TESTS
=
invalid-name missing-docstring
\
redefined-variable-type too-few-public-methods duplicate-code
\
too-many-locals too-many-branches too-many-arguments
\
too-many-return-statements
too-many-return-statements
import-error
IGNORED_PYLINT2_TESTS
=
superfluous-parens
IGNORED_PYLINT3_TESTS
=
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment