19 lines
370 B
Text
19 lines
370 B
Text
:- module hailstone.
|
|
|
|
:- interface.
|
|
|
|
:- import_module int, list.
|
|
|
|
:- func hailstone(int) = list(int).
|
|
:- pred hailstone(int::in, list(int)::out) is det.
|
|
|
|
:- implementation.
|
|
|
|
hailstone(N) = S :- hailstone(N, S).
|
|
|
|
hailstone(N, [N|S]) :-
|
|
( N = 1 -> S = []
|
|
; N mod 2 = 0 -> hailstone(N/2, S)
|
|
; hailstone(3 * N + 1, S) ).
|
|
|
|
:- end_module hailstone.
|