From a2b6b78630d6f10d9a6e63aa07253aa25acbebde Mon Sep 17 00:00:00 2001 From: Jason Staten Date: Sun, 17 Nov 2019 20:54:48 -0700 Subject: [PATCH] recursive word count --- erlang/words.erl | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 erlang/words.erl diff --git a/erlang/words.erl b/erlang/words.erl new file mode 100644 index 0000000..6b91529 --- /dev/null +++ b/erlang/words.erl @@ -0,0 +1,9 @@ +-module(words). +-export([count/1]). + +count(S) -> count(S, true, 0). + +count("", _, Total) -> Total; +count([$ |Tail], _, Total) -> count(Tail, true, Total); +count([_|Tail], false, Total) -> count(Tail, false, Total); +count([_|Tail], true, Total) -> count(Tail, false, Total + 1). \ No newline at end of file