All pastes #636581 Raw Edit

Someone

public text v1 · immutable
#636581 ·published 2007-07-28 01:18 UTC
rendered paste body

/* listof(X,C,L) is true iff L is a List of length X where each entry is C */
listof([],_).

listof(L,C) :-
	L = [Head|Tail],
	Head = C,
	listof(Tail,C).

myencode(L,R) :-
	R = [[X,C]],
	length(L,X),
	listof(L,C).

myencode(L,R) :-

	
	R = [[N,X],[M,Y]|Z],
	/* X \== Y, */
	myencode(A,[[N,X]]),
	append(A,B,L),
	myencode(B,[[M,Y]|Z]).
	


mynewencode(L,R) :-
	R = [[N,C]],
	length(L,N),
	listof(L,C).


mynewencode(L,R) :-
	R = [[N,C]|Tail],
	length(A,N),
	listof(A,C),
	append(A,B,L),
	myencode(B,Tail).
	


	


mydecode(L,R) :-
	myencode(R,L).