Skip to content

Instantly share code, notes, and snippets.

@scsibug
Created February 9, 2012 01:08
Show Gist options
  • Save scsibug/1776163 to your computer and use it in GitHub Desktop.
Save scsibug/1776163 to your computer and use it in GitHub Desktop.
string_words erlang
-module(string_words).
-export([word_count/1]).
%Write a function that uses recursion to return the number of words in a string.
word_count([]) -> 0;
word_count([32]) -> 0;
word_count([_]) -> 1;
word_count([32|T]) -> word_count(T);
word_count([H|32]) -> word_count(H);
word_count([_,32|T]) -> 1+word_count(T);
word_count([_|T]) -> word_count(T).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment