Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
teaching
AI
Commits
644cf7a3
Commit
644cf7a3
authored
Nov 14, 2018
by
Marius Frinken
Browse files
marius' stuff for the third tutorial session
parent
4e713c13
Changes
2
Hide whitespace changes
Inline
Side-by-side
Marius/uebung03/tips.pl
0 → 100644
View file @
644cf7a3
%sometimes you may want to "tag" things onto a existing data structure
% e.g. process(ListOfTriples) needs a list of triples
%but you only have a list of pairs
process
(
ListOfTriples
):-
%does something
write
(
ListOfTriples
).
%now we need to merge .i.e tag on a dummy value 0 in our naive case here
tag_on
([(
A
,
B
)],[(
A
,
B
,
0
)]).
tag_on
([(
A
,
B
)|
Tail
],
ListOfTriples
):-
tag_on
(
Tail
,
TempListOfTriples
),
ListOfTriples
=
[(
A
,
B
,
0
)|
TempListOfTriples
],!.
tag_and_process
(
List
):-
tag_on
(
List
,
NewList
),
process
(
NewList
).
%Prolog offers multiple ways of sorting, this is one
comp_triples
(
Delta
,
(
C1
,
_
,
_
),(
C2
,
_
,
_
)):-
compare
(
Delta
,
C1
,
C2
).
my_sort
(
ListOfTriples
,
SortedListOfTriples
):-
predsort
(
comp_triples
,
ListOfTriples
,
SortedListOfTriples
).
%testcase
test_my_sort
(
X
):-
my_sort
([(
29
,
"E"
,
"E"
),(
13
,
"E"
,
"E"
),(
54
,
"E"
,
"E"
),(
9
,
"E"
,
"E"
)],
X
).
%normal lists can bes sorted with sort(List,SortedList)
%interface for your homework:
% dfs(GoalValue, Tree, PathString, Cost)
%
% GoalValue is a String e.g. "G"
% Tree is a tree e.g. tree("A",[(1,tree("B",[]))])
% PathString shall contain the correct path from the beginning straight to the goal in the end
% if you do not like strings, you may implement path as list
% Cost is a number that shall contain the summed up cost in the end
%Only the iterative deepening differs from that interface, as we have to give a Stepsize:
% idfs(GoalValue,Tree,PathString,Cost,StepSize)
% also please use write or any other form of writing to show the order in whch your code expands the nodes
% that helps you and us to determine whether you code actually performs a BFS, DFS and so on
% (and you could verify your answer to 3.1 with that technique)
Marius/uebung03/uebung03.pdf
0 → 100644
View file @
644cf7a3
File added
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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