Hailstone Numbers

I just did the most recent Programming Praxis, Hailstones

Here’s my solution in Erlang.

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

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.