Alex
Alex

Reputation: 63

Run Length Encoding Issue - Have [ ]s need ( )s

I'm trying to do a run length encoding problem and I think I more or less have it thanks to other questions on this topic on this site and others, however the format its returning in is not being accepted by my Uni's IDE. Could anyone help me?

This is my program

count([],[]).
count([X|T],[[X,C1]|R]) :- count(T,[[X,C]|R]), !, C1 is C+1.
count([X|T],[[X,1]|R]) :- count(T,R).

And this returns

?- count([1,1,1,2,2,2,3,1,1],R).
R = [[1, 3], [2, 3], [3, 1], [1, 2]].

However what the system wants it to return is

?- count([1,1,1,2,2,2,3,1,1],R).
R = [(1, 3), (2, 3), (3, 1), (1, 2)].

It wants tuples instead of lists, does anyone have any idea how to make this happen?

Upvotes: 0

Views: 48

Answers (1)

Isabelle Newbie
Isabelle Newbie

Reputation: 9378

To construct a tuple, simply write (A, B) wherever you have written a term of the form [A, B].

Upvotes: 1

Related Questions