Created
February 9, 2012 01:08
-
-
Save scsibug/1776163 to your computer and use it in GitHub Desktop.
string_words erlang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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