Just Code‎ > ‎

Erlang - Gissa talet

posted Aug 27, 2009, 1:25 AM by Peter Henell
%%%-------------------------------------------------------------------
%%% File : test.erl
%%% Author : <MrM@EBRA>
%%%-------------------------------------------------------------------
%%% File : test.erl
%%% Author : <MrM@EBRA>
%%% Description :
%%%
%%% Created : 3 Jan 2009 by <MrM@EBRA>
%%%-------------------------------------------------------------------
-module(test).

-export([start/0, loop/1, init/0]).

start()
->
spawn(test, init, []).

init()
->
loop(random:uniform(
100)).

loop(Talet)
->
receive
Guess
->
if
Guess
> Talet ->
io:format(
"~p~n", ["To big"]),
loop(Talet);
Guess
< Talet ->
io:format(
"~p~n", ["To small"]),
loop(Talet);
true ->
io:format(
"~p~n", ["WIN!"])
end
end.
Comments