Skip to content

Instantly share code, notes, and snippets.

@nkoneko
Last active August 29, 2015 14:04
Show Gist options
  • Save nkoneko/5f95e3bf57be6a2077d4 to your computer and use it in GitHub Desktop.
Save nkoneko/5f95e3bf57be6a2077d4 to your computer and use it in GitHub Desktop.
-module(concurrent1).
-export([pong/0, ping/1, start/1]).
pong() ->
receive
{From, Msg} ->
io:format("Pong received ~w~n", [Msg]),
From ! {self(), Msg},
pong();
term ->
io:format("Bye~n", [])
end.
ping(0) ->
pongProc ! term,
io:format("Bye~n", []);
ping(M) ->
pongProc ! {self(), hello},
receive
{From, Msg} ->
io:format("Ping received ~w~n", [Msg])
end,
ping(M - 1).
start(M) ->
PongPid = spawn(concurrent1, pong, []),
register(pongProc, PongPid),
spawn(concurrent1, ping, [M]).
-module(list1).
-export([min/1, max/1, min_max/1]).
min([Head | Rest]) ->
min_(Rest, Head).
max([Head | Rest]) ->
max_(Rest, Head).
min_([], Result) ->
Result;
min_([Head | Rest], ResultSoFar) when ResultSoFar > Head ->
min_(Rest, Head);
min_([_ | Rest], ResultSoFar) ->
min_(Rest, ResultSoFar).
max_([], Result) ->
Result;
max_([Head | Rest], ResultSoFar) when ResultSoFar < Head ->
max_(Rest, Head);
max_([_ | Rest], ResultSoFar) ->
max_(Rest, ResultSoFar).
min_max(List) ->
{list1:min(List), list1:max(List)}.
-module(temp).
-export([convert/1]).
f2c(F) ->
5 * (F - 32) / 9.
c2f(C) ->
9 * C / 5 + 32.
convert({c, X}) ->
{f, c2f(X)};
convert({f, Y}) ->
{c, f2c(Y)}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment