The problem that I am trying to solve is as follows: Write an Erlang function named collatz that takes one argument N. You may assume that N is an integer 1 or larger. The function should print the Collatz sequence (one number per line) starting with N. For example, collatz( 4 ) should print 4, 2, 1 (on separate lines). collatz( 6 ) should print 6, 3, 10, 5, 16, 8, 4, 2, 1 (on separate lines).
The collatz function that I have written is working properly but I am having difficulty in printing the output on separate lines. The commented-out part of the code below is my attempt to generate the output on separate lines.
collatz(1) -> [1];
collatz(N) when N rem 2 == 0 ->
[N|collatz(N div 2)];
%[io:format("Collatz is : ~p~n",[N])N|collatz(N div 2)];
collatz(N) ->
[N|collatz(3*N+1)].
%[io:format("Collatz is : ~p~n",[N])N|colla[N|collatz(N div 2)]tz(3*N+1)].
The output that I get when I call for example collatz(5) is [5,16,8,4,2,1]. I want these numbers to be printed out on separate lines.