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
01a32079
Commit
01a32079
authored
Jan 17, 2017
by
Vít Novotný
Browse files
added examples 1.2_16 and 2.5.1_10
parent
3dc228e3
Changes
4
Hide whitespace changes
Inline
Side-by-side
1.2_16.pl
0 → 100644
View file @
01a32079
% nacteni:
/*
['1.2_16.pl'].
*/
tiskniseznam
(
S
):-
write
(
'seznam=['
),
nl
,
tiskniseznam
(
S
,
1
).
tiskniseznam
([],
_
):-
write
(
']'
),
nl
.
tiskniseznam
([
H
|
T
],
N
):-
tab
(
4
),
write
(
N
),
write
(
': '
),
write
(
H
),
nl
,
N1
is
N
+
1
,
tiskniseznam
(
T
,
N1
).
% demonstracni vypis
% abychom se vyhli varovanim "Redefined static procedure ..."
:-
dynamic
start
/
0
.
start
:-
write
(
'Program vytiskne zadany seznam. Napr.:'
),
nl
,
nl
,
write
(
'Vysledek dotazu "tiskniseznam([a, b, c])." je:'
),
nl
,
tiskniseznam
([
a
,
b
,
c
]),
nl
,
write
(
'Vysledek dotazu "tiskniseznam([a, b, [c1, c2, c3], d, `mezi d a e`, e])." je:'
),
nl
,
tiskniseznam
([
a
,
b
,
[
c1
,
c2
,
c3
],
d
,
'mezi d a e'
,
e
]).
?-
start
.
:-
retractall
(
write_all_X
/
3
).
:-
retractall
(
start
/
0
).
1.2_16.py
0 → 100644
View file @
01a32079
#!/usr/bin/env python
# encoding=utf-8 (pep 0263)
def
tiskniseznam
(
xs
):
i
=
1
print
(
"seznam=["
)
while
xs
!=
None
:
print
(
" %d: %s"
%
(
i
,
xs
[
0
]))
i
=
i
+
1
xs
=
xs
[
1
]
print
(
"]"
)
# demonstracni vypis
if
__name__
==
"__main__"
:
print
(
"Program vytiskne zadany seznam. Napr.:
\n
"
)
print
(
"Vysledek volani tiskniseznam(('a', ('b', ('c', None)))) je:
\n
"
)
tiskniseznam
((
'a'
,
(
'b'
,
(
'c'
,
None
))))
print
(
"
\n\n
Vysledek volani tiskniseznam(('a', ('b', (['c1', 'c2', 'c3'], "
+
"('d', ('mezi d a e', ('e', None))))))). je:
\n
"
)
tiskniseznam
((
'a'
,
(
'b'
,
([
'c1'
,
'c2'
,
'c3'
],
(
'd'
,
(
'mezi d a e'
,
(
'e'
,
None
)))))))
print
(
""
)
2.5.1_10.pl
0 → 100644
View file @
01a32079
% nacteni:
/*
['2.5.1_10.pl'].
*/
:-
retractall
(
start
/
0
).
:-
retractall
(
qsort
/
2
).
:-
retractall
(
divide
/
4
).
:-
dynamic
qsort
/
2
,
divide
/
4
.
qsort
([],[])
:-
!.
qsort
([
H
],[
H
])
:-
!.
qsort
([
H
|
T
],
L
)
:-
divide
(
H
,
T
,
M
,
V
),
qsort
(
M
,
M1
),
qsort
(
V
,
V1
),
append
(
M1
,[
H
|
V1
],
L
).
divide
(
_
,[],[],[])
:-
!.
divide
(
H
,[
K
|
T
],[
K
|
M
],
V
)
:-
K
=<
H
,
!,
divide
(
H
,
T
,
M
,
V
).
divide
(
H
,[
K
|
T
],
M
,[
K
|
V
])
:-
K
>
H
,
divide
(
H
,
T
,
M
,
V
).
% demonstracni vypis
% abychom se vyhli varovanim "Redefined static procedure ..."
:-
dynamic
start
/
0
.
start
:-
write
(
'Radici algoritmus QuickSort'
),
nl
,
nl
,
write
(
'Vysledek volani "qsort([5, 2, 8, 2, 654, 8, 3, 4], L)":'
),
nl
,
qsort
([
5
,
2
,
8
,
2
,
654
,
8
,
3
,
4
],
L
),
write
(
'L = '
),
write
(
L
),
nl
.
?-
start
.
:-
retractall
(
start
/
0
).
2.5.1_10.py
0 → 100644
View file @
01a32079
#!/usr/bin/env python
# encoding=utf-8 (pep 0263)
from
linked_lists
import
LinkedList
,
Cons
,
Nil
def
append
(
xs
,
ys
):
if
xs
==
Nil
:
return
ys
else
:
return
Cons
(
xs
.
head
,
append
(
xs
.
tail
,
ys
))
def
qsort
(
xs
):
if
xs
==
Nil
:
return
Nil
if
xs
.
tail
==
Nil
:
return
xs
ms
,
vs
=
divide
(
xs
.
head
,
xs
.
tail
)
return
append
(
qsort
(
ms
),
Cons
(
xs
.
head
,
qsort
(
vs
)))
def
divide
(
h
,
xs
):
if
xs
==
Nil
:
return
(
Nil
,
Nil
)
ms
,
vs
=
divide
(
h
,
xs
.
tail
)
if
xs
.
head
<=
h
:
return
(
Cons
(
xs
.
head
,
ms
),
vs
)
else
:
return
(
ms
,
Cons
(
xs
.
head
,
vs
))
# demonstracni vypis
if
__name__
==
"__main__"
:
print
(
"Radici algoritmus QuickSort
\n
"
)
print
(
"qsort(LinkedList(5, 2, 8, 2, 654, 8, 3, 4)):
\n\t
%s
\n
"
%
\
qsort
(
LinkedList
(
5
,
2
,
8
,
2
,
654
,
8
,
3
,
4
)))
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