diff options
author | Nathan Lasseter <nathan.je.lasseter@googlemail.com> | 2009-10-04 00:56:56 +0100 |
---|---|---|
committer | Nathan Lasseter <nathan.je.lasseter@googlemail.com> | 2009-10-04 00:56:56 +0100 |
commit | 0248ed34ce3d05228bc5084669c3a27933be0c2e (patch) | |
tree | b9c4990344b0863a2af851b5917c49f3a5f03e6b /problem14.erl | |
parent | 00686037d57eb0a0d5eba6eeb6fcc9692e8b59f6 (diff) |
first commit
Diffstat (limited to 'problem14.erl')
-rwxr-xr-x | problem14.erl | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/problem14.erl b/problem14.erl new file mode 100755 index 0000000..335c269 --- /dev/null +++ b/problem14.erl @@ -0,0 +1,29 @@ +-module(problem14). +-export([solve/0]). + +solve() -> + rep(1,1000000,1,1). + +do(N, C) -> + if + N == 1 -> + C; + N rem 2 == 0 -> + do((N div 2), (C + 1)); + N rem 2 > 0 -> + do(((3 * N) + 1), (C + 1)) + end. + +rep(Num, Max, Top, TN) -> + if + Num > Max -> + TN; + true -> + L = do(Num, 1), + if + L > Top -> + rep((Num + 1), Max, L, Num); + true -> + rep((Num + 1), Max, Top, TN) + end + end. |