Paste number 64563: manorboy

Paste number 64563: manorboy
Pasted by: roller
When:11 months, 1 day ago
Share:Tweet this! | http://paste.lisp.org/+1DTF
Channel:None
Paste contents:
Raw Source | XML | Display As
-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.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.