From 8172bdd6bdc9523ebde5dd8c1022e971c0299ada Mon Sep 17 00:00:00 2001 From: Guillermo Ramos Date: Tue, 8 May 2012 23:57:54 +0200 Subject: [Erlang] Día 1 --- erlang/.gitignore | 1 + erlang/basic.erl | 4 ++++ erlang/count.erl | 5 +++++ erlang/factorial.erl | 9 +++++++++ erlang/match.erl | 5 +++++ erlang/matching_function.erl | 6 ++++++ erlang/words.erl | 6 ++++++ 7 files changed, 36 insertions(+) create mode 100644 erlang/.gitignore create mode 100644 erlang/basic.erl create mode 100644 erlang/count.erl create mode 100644 erlang/factorial.erl create mode 100644 erlang/match.erl create mode 100644 erlang/matching_function.erl create mode 100644 erlang/words.erl (limited to 'erlang') diff --git a/erlang/.gitignore b/erlang/.gitignore new file mode 100644 index 0000000..17278c0 --- /dev/null +++ b/erlang/.gitignore @@ -0,0 +1 @@ +*.beam diff --git a/erlang/basic.erl b/erlang/basic.erl new file mode 100644 index 0000000..c7095ed --- /dev/null +++ b/erlang/basic.erl @@ -0,0 +1,4 @@ +-module(basic). +-export([mirror/1]). + +mirror(Anything) -> Anything. diff --git a/erlang/count.erl b/erlang/count.erl new file mode 100644 index 0000000..72cb378 --- /dev/null +++ b/erlang/count.erl @@ -0,0 +1,5 @@ +-module(count). +-export([count/1]). + +count(10) -> io:fwrite("10~n"); +count(N) -> io:fwrite("~b~n", [N]), count(N+1). diff --git a/erlang/factorial.erl b/erlang/factorial.erl new file mode 100644 index 0000000..f423c7c --- /dev/null +++ b/erlang/factorial.erl @@ -0,0 +1,9 @@ +-module(factorial). +-export([fact/1, fib/1]). + +fact(0) -> 1; +fact(N) -> N * fact(N-1). + +fib(0) -> 1; +fib(1) -> 1; +fib(N) -> fib(N-1) + fib(N-1). diff --git a/erlang/match.erl b/erlang/match.erl new file mode 100644 index 0000000..016cbbc --- /dev/null +++ b/erlang/match.erl @@ -0,0 +1,5 @@ +-module(match). +-export([match/1]). + +match(success) -> io:fwrite("success~n"); +match({error, Message}) -> io:fwrite("error: ~s~n", [Message]). diff --git a/erlang/matching_function.erl b/erlang/matching_function.erl new file mode 100644 index 0000000..178f189 --- /dev/null +++ b/erlang/matching_function.erl @@ -0,0 +1,6 @@ +-module(matching_function). +-export([number/1]). + +number(one) -> 1; +number(two) -> 2; +number(three) -> 3. diff --git a/erlang/words.erl b/erlang/words.erl new file mode 100644 index 0000000..4eb0354 --- /dev/null +++ b/erlang/words.erl @@ -0,0 +1,6 @@ +-module(words). +-export([words/1]). + +words([]) -> 1; +words([32|Tail]) -> 1 + words(Tail); +words([_|Tail]) -> words(Tail). -- cgit v1.2.3