dragonwasrobot / learn-prolog-now-exercises

My solutions to the exercises and practical sessions of the book 'Learn Prolog Now!' by Patrick Blackburn, Johan Bos, and Kristina Striegnitz.
288 stars 81 forks source link

Update Exercise 6.5 to not use helper functions #32

Closed sohamsadhu closed 8 years ago

sohamsadhu commented 8 years ago

For swapfl assumption is made that empty list and list with one element will return false given they do not have first and last element. This assumption is based on strict interpretation of question that it needs to compare the first and last elements. On this assumption base case is made with two elements swapped, and inductive case with head and tail being different but elements in between are same.

This allows to define swapfl in terms of itself, without any extra helper functions.

sohamsadhu commented 8 years ago

Closing the pull request as the given solution is not optimal; and not generic enough.