Since I am stuck at home with nothing to do due to the virus I've decided to start learning Prolog I've been working through different questions from learn Prolog and from 99 Prolog problems.
I am currently stuck on a Run Length Encoding question and would appreciate any help or guidance regarding the problem.
Here is the question I am stuck on:
Write a predicate encode/2 that takes the uncompressed list as a first parameter and returns the compressed list as shown as the second parameter. For example:
encode(['a','b','b','c','c','c','d','d'],X) should yield X = [ (a, 1), (b, 2), (c, 3), (d, 2)] .
encode(['a','p','p','l','e'],X) should yield X = [ (a, 1), (p, 2), (l, 1), (e, 1)] .```
And then to decode it:
Write a predicate decode/2 that takes the compressed list as a first parameter and returns the uncompressed list as shown as the second parameter. For example:
```decode([],X) should yield X = [].
decode([(a,1), (b,2), (c,3), (d,2)],X) should yield X = ['a','b','b','c','c','c','d','d'] .
decode([(a,1), (p,2), (l,1), (e,1)],X) should yield X = ['a','p','p','l','e'].```