Not logged in. · Lost password · Register

Jazzpirate
Member since Oct 2016
803 posts
Subject: First Homework Assignment
The first exercise sheet is now online on studon.

Please upload your solutions by friday next week (Nov. 2.) via studon in one and only one of the four tutorials, and please stick with that tutorial for the rest of the semester, as to not cause confusion when we compute your full bonus points at the end of the semester ;) If you need to switch, please let us know so we can keep track of your points properly.

If you can't use studon (apparently there's a problem with erasmus students), please pick one tutorial which suits your schedule best and send your solutions directly to you tutor (via email or whatever they prefer).

In general we strongly prefer pdf for text and plain source files for programming exercises (exceptions will be stated explicitly). In programming exercises, please document your code generously with comments, it will only make your tutor's lives easier and hence more inclined to be generous ;)

If you have any questions regarding the exercises (except for actual solutions, of course), don't hesitate to ask here - usually you're not the only one who would like to hear the answer ;)
Stella
Member since Apr 2018
28 posts
Is it fine to solve the permutations without the hint? The hint confuses me more than it helps.

Also: Any hints on how to hand in stuff on studon without getting the pesky .sec ending?
This post was edited on 2018-10-27, 04:04 by Stella.
Jonas S
Member since Jul 2016
91 posts
Regarding Question 1.2.3: What is a symmetrical binary tree? I couldn't find any definition in the lecture notes.
tyr
Avatar
Member since Oct 2014
93 posts
In reply to post #2
+1 Stella
Is it fine to solve the permutations without the hint? The hint confuses me more than it helps.
Yes, as long as it written in Prolog and it works, you can solve the problem however you like. You just might get lost in the process, that's why we gave the hint. But I totally agree that the way it is written may confuse you, so you may hear it with my words.

The helper function takeout(X,LSA,LSB) might be helpful, as it takes the element X and a List LSB and "returns" a List LSA, where X was put into the list. By re-evaluating the function (space bar or using the ";"), you should get a different LSA, meaning that X is at another location in the list.

swipl example:
?- takeout(1,X,[2,3,4]).
X = [1, 2, 3, 4] ;
X = [2, 1, 3, 4] ;
X = [2, 3, 1, 4] ;
X = [2, 3, 4, 1] ;
false.

(This also shows the "magic" of Prolog, since the definition of the function "changes" by changing the variable parameters. But what you should learn from here is, that the definition does not change, since both descriptions of takeout are correct. Once you realize this, the only two things left you need to become good at Prolog is a good understanding of recursion and the will to learn Prolog's syntax ;)

Also: Any hints on how to hand in stuff on studon without getting the pesky .sec ending?
No, not really. What file format did you hand in?
"Debugging is like doing surgery by randomly squeezing stuff in a patient's body and going like 'lmao tell me when this guy stops breathing'." -- Orteil, Creator of Cookie-Clicker
This post was edited 2 times, last on 2018-10-28, 09:53 by tyr.
Jazzpirate
Member since Oct 2016
803 posts
+1 Stella
Also: Any hints on how to hand in stuff on studon without getting the pesky .sec ending?
Nope, studon just does that. Nevermind that, the tutors will have to take care of that unfortunately.

Regarding Question 1.2.3: What is a symmetrical binary tree? I couldn't find any definition in the lecture notes.
If you google "symmetrical binary tree", you will find two definitions; one being on the structure of the tree and one being on the values of the tree. Only one of them makes sense in the context of the exercise ;)
F.W.
Member since Oct 2018
4 posts
I have a general question regarding the prolog assignments. As far as I understood the exercise, we are not allowed to use any built-in functions. Is that correct? Or should we just not use the built-in functions that we are required to implement ourselves (i.e. "delete", "reverse") but can use others, such as "append"?
Jazzpirate
Member since Oct 2016
803 posts
As far as I understood the exercise, we are not allowed to use any built-in functions. Is that correct?
Let me put it like that: You are not supposed to use any pre-defined functions on lists. But of course you'll need to pattern match lists, and I can't reasonably expect you to reimplement a pattern matching mechanism :D (bonus points if you do xD )
EinGartenzwerg
Member since Oct 2018
10 posts
One short question regarding the zip function:
if zip() gets lists that differ by more than 1, how should it react? Or is it irrelevant and simply not specified?

mfg
Nash
Member since May 2014
48 posts
Since the assignment says:
The zip function takes two lists with lengths that differ at most by 1
I would assume, that any other case is irrelevant

I have a question regarding myPermutation: is this function supposed to output false at the end? It's not on the sheet, but the permutation built-in also outputs false at the end
tyr
Avatar
Member since Oct 2014
93 posts
Quote by Nash:
Since the assignment says:
The zip function takes two lists with lengths that differ at most by 1
I would assume, that any other case is irrelevant
You are  right.
I have a question regarding myPermutation: is this function supposed to output false at the end?


Yes,  at least our solution does this
"Debugging is like doing surgery by randomly squeezing stuff in a patient's body and going like 'lmao tell me when this guy stops breathing'." -- Orteil, Creator of Cookie-Clicker
ghosty
Member since Dec 2014
61 posts
Should construct fail if the given list is not duplicate-free?
E.g. should construct([1, 2, 3], T) and construct([1, 1, 2, 3], T) both yield the same result T = t(1, nil, t(2, nil, t(3, nil, nil))) or should the second one say "false"?
Jazzpirate
Member since Oct 2016
803 posts
In reply to post #9
I have a question regarding myPermutation: is this function supposed to output false at the end?
This is Prologs default behaviour: For prolog, every query is "find a proof/substitution that makes the queried statement true". If it finds such a substitution, it will return that. If it doesn't it will return false. So basically any "function" (i.e. predicate) should return false if and only if no other solutions for the free variables in a query remain.

if zip() gets lists that differ by more than 1, how should it react?
By the above: Since you're not supposed to implement functionality for this case, Prolog would have to return false by default.

Should construct fail if the given list is not duplicate-free?
E.g. should construct([1, 2, 3], T) and construct([1, 1, 2, 3], T) both yield the same result T = t(1, nil, t(2, nil, t(3, nil, nil))) or should the second one say "false"?
pff, to be honest, I didn't even consider that case, so either behavior is fine, since it's unspecified by the framing of the problem :)
Orlan
Avatar
Member since May 2017
146 posts
Quote by Exercise Sheet:
Write a ProLog function construct that constructs a binary tree out of a list of (distinct)
numbers [...]

I guess we can assume that the given list is duplicate-free since the exercise sheet tells us it is a list of distinct numbers, right?
Jazzpirate
Member since Oct 2016
803 posts
I guess we can assume that the given list is duplicate-free since the exercise sheet tells us it is a list of distinct numbers, right?
Yes, you can. I've interpreted the previous question as a sort-of fallback. What we care about is whether your predicate behaves as intended on "valid" inputs only -- I assume you know to throw exceptions in real-life situations ;)
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
Datenschutz | Kontakt
Powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2011 by Yves Goergen