| Paste number 64563: | manorboy |
| Pasted by: | roller |
| When: | 1 year, 7 months ago |
| Share: | Tweet this! | http://paste.lisp.org/+1DTF |
| Channel: | None |
| Paste contents: |
-module(manorboy).
-export([manorboy/0, manorboy/1]).
kloop(K) ->
receive
{decr,Pid} -> Pid ! K-1, kloop(K-1);
_ -> ok
end.
a(K, X1, X2, X3, X4, X5) ->
Kproc = spawn(fun() -> kloop(K) end),
B = fun (B) ->
Kproc ! {decr, self()},
receive Kdecr ->
a(Kdecr, fun() -> B(B) end, X1, X2, X3, X4)
end
end,
if
K =< 0 -> Kproc ! X4() + X5();
true -> Kproc ! B(B)
end.
manorboy([Nstr]) ->
{N, _ } = string:to_integer(Nstr),
Res = manorboy(N),
io:format("~p~n", [Res]),
Res;
manorboy(N) ->
a( N, fun() -> 1 end, fun() -> -1 end, fun() -> -1 end, fun() -> 1 end, fun() -> 0 end ).
manorboy() ->
manorboy(10).
This paste has no annotations.