Question: Run Length Encoding in Prolog Run Length Enconding ( RLE ) is a compression technique used in areas such as image compression ( e .

Run Length Encoding in Prolog
Run Length Enconding (RLE) is a compression technique used in areas such as image compression (e.g. GIFs). It compresses runs of identical pieces of information (in this case single-character atoms) and records how many times they appear in a list in a consecutive run. For example, the list:
['a','a','a','b','b','c','a','a']
will get encoded to:
[('a',3),('b',2),('c',1),('a',2)]
Write a predicate myencode/2 that takes the uncompressed list as a first parameter and returns the compressed list as shown as the second parameter. For example:
myencode([],X) should yield X =[].
myencode(['a','b','b','c','c','c','d','d'],X) should yield X =[(a,1),(b,2),(c,3),(d,2)].
myencode(['a','p','p','l','e'],X) should yield X =[(a,1),(p,2),(l,1),(e,1)].
Hint:
You may find it useful to write a tempencode/2 function that translates a list like
['a','a','a','b','b','c','a','a']
into
[('a',1),('a',1),('a',1),('b',1),('b',1),('c',1),('a',1),('a',1)]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!