Python Solutions to [https://prof.ti.bfh.ch/hew1/informatik3/prolog/p-99/ 99 Prolog Prolems].
Index TableOfContents(2)
Problems 1-6
André Roberge has a zip file with solutions to the first six problems, in Crunchy format: [http://crunchy.googlecode.com/files/first_6_of_99_problems.zip First six]
Problem 7: Flatten a nested list structure
Based on the standard library documentation:
from itertools import chain def flatten(listOfLists): return list(chain(*listOfLists))
The suggested solution does not work for a list like the following:
a_list = [0, 1, [2, 3], 4, 5, [6, 7]]
Problem 8: Eliminate consecutive duplicates of list elements
from itertools import groupby def compress(alist): return [key for key, group in groupby(alist)]