Skip to content

Instantly share code, notes, and snippets.

@psyomn
Created March 11, 2013 13:38
Show Gist options
  • Save psyomn/5134288 to your computer and use it in GitHub Desktop.
Save psyomn/5134288 to your computer and use it in GitHub Desktop.
Some Erlang scripts I wrote some time ago for practice.
-module(lists1).
-author(psyomn).
-export([mymin/1,mymax/1,min_max/1,swedish_date/0]).
mymin([H|T]) -> mymin(T,H).
mymin([],Acc) -> Acc;
mymin([H|T],Acc) when H < Acc -> mymin(T,H);
mymin([_|T],Acc) -> mymin(T,Acc).
mymax([H|T]) -> mymax(T,H).
mymax([],Acc) -> Acc;
mymax([H|T],Acc) when H > Acc -> mymax(T,H);
mymax([_|T],Acc) -> mymax(T,Acc).
min_max(L) -> {mymin(L),mymax(L)}.
swedish_date() ->
{Y,M,D} = erlang:date(),
SwedY = Y rem 100,
Final = swedish_date([SwedY,M,D],[]),
FString = lists:map(fun(X) -> integer_to_list(X) end, Final),
io:format(lists:flatten(FString)).
swedish_date([],Stack) -> Stack;
swedish_date([H|T],Stack) ->
case H < 10 of
true -> swedish_date(T,[0,H|Stack]);
_ -> swedish_date(T,[H|Stack])
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment