Created
June 8, 2018 01:27
-
-
Save eddieantonio/a5bd955b91f74913e8a09a12c2cbf36c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env escript | |
-module(digital). | |
-import(lists, [sum/1]). | |
-export([main/1, root/1, dr/1]). | |
main([Number]) -> | |
Answer = root(list_to_integer(Number)), | |
io:format("~p~n", [Answer]); | |
main(_) -> | |
halt(1). | |
root(N) when N >= 0, N =< 9 -> | |
N; | |
root(N) -> | |
Digits = integer_to_list(N), | |
root(sum_digits(Digits)). | |
sum_digits(Digits) -> | |
sum([X band 16#0F || X <- Digits]). | |
dr(N) -> 1 + ((N - 1) rem 9). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment