You are viewing a single comment's thread. Return to all comments →
Erlang Solution. There is a built in abs(X) function, but I rolled my own just for the practice.
-module(solution). -export([main/0]). read(NewList) -> case io:fread("", "~d") of {ok, [NewElement]} -> read(NewList ++ [NewElement]); _ -> NewList end. absValue(X) when X >= 0 -> X; absValue(X) when X < 0 -> X * -1; absValue(_) -> ok. main() -> List = read([]), AbsList = [absValue(N) || N <- List], [io:format("~p~n", [A]) || A <- AbsList].
Update List
You are viewing a single comment's thread. Return to all comments →
Erlang Solution. There is a built in abs(X) function, but I rolled my own just for the practice.