I am trying to create a function called collatz_list
in Prolog. This function takes two arguments, the first one is a number and the second in a list. This list will be my output of this function. So, here's my function:
collatz_list(1,[1]).
collatz_list(N,[H|T]) :-
N > 1,
N mod 2 =:= 0,
collatz_list(N, [H|T]).
collatz_list(N,[H|T]) :-
N > 1,
N mod 2 =:= 1,
N is N*3 +1,
collatz_list(N,[H|T]).
I am struggling with creating the output list. Can anyone help me on that?
Thanks.