Hailstone Numbers

I just did the most recent Programming Praxis, Hailstones

Here’s my solution in Erlang.

-module(hailstones).
-export([hailseq/1,hail/1]).

hail(1) -> 1;
hail(N) when N > 1, (N rem 2) == 0, is_integer(N) -> N div 2;
hail(N) when N > 1, (N rem 2) > 0, is_integer(N) -> 3*N+1.
hailseq(1) -> 1;
hailseq(N) when is_integer(N) -> io:fwrite("~w ", [N]), hailseq(hail(N)).

Leave a Reply

Your email address will not be published. Required fields are marked *