0

The problem is, I'm not sure how to implement it, I thought about adding another parameter to the function, And then compare the two integers and if the second one is bigger as the first one, ad the second one to the list and decrements the second one , like B is B-1, ant then call recursively the Function to compare the first integer with the second one decremented, adding it to the list every time if its bigger. Does anyone have an idea how to implement it tail-recursively in Prolog?

lurker
  • 56,987
  • 9
  • 69
  • 103
Erry07
  • 29
  • 1
  • 2
  • 5
  • Do you want to implement the code yourself (to learn how to do it)? Or can you use library predicates offered by your Prolog processor? – repeat Dec 13 '15 at 16:29
  • the only library pradicate im supposed to use is reverse, but to answer your question , yes, it is form me to implement te cod, to learn how to do it. – Erry07 Dec 13 '15 at 16:41
  • 1
    Then this question could interest you: http://stackoverflow.com/questions/6792730/fill-list-in-swi-prolog/30047316 – repeat Dec 13 '15 at 16:58
  • As i see it in te explenations, in the last answer, ist presented a funktion to se if an integer is part of a List, but, in my case i don´t need to see if the integer is parte of the list, but to generate the list with the two integers given and filled with the other integers in between, so i don´t get how it schould help me :) – Erry07 Dec 13 '15 at 17:19
  • Can't you think through the linked question and adopt that code to what you need? There should be plenty of ideas there to help you get started. You should show some attempt at solving the problem and ask a more specific question where you get stuck. In your question, you mentioned, *I thought about adding...*. Did you actually write some code and try it? – lurker Dec 14 '15 at 17:30
  • This problem is so trivial it would be very hard to help without providing the complete solution. Look at other instances of Prolog arithmetic and recursive procedures and you will figure it out. – Daniel Lyons Dec 14 '15 at 20:42

0 Answers0