Created
June 25, 2012 12:02
-
-
Save pedrosnk/2988194 to your computer and use it in GitHub Desktop.
Learning Erlang
This file contains hidden or 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
% First Code Kata from http://projecteuler.net/problem=1 | |
% If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. | |
% Find the sum of all the multiples of 3 or 5 below 1000. | |
-module(problem1). | |
-export([populate_list/1]). | |
-export([go/0]). | |
populate_list(1) -> []; | |
populate_list(Number) when (Number rem 3 == 0) or (Number rem 5 == 0) -> | |
[Number] ++ populate_list(Number - 1); | |
populate_list(Number) -> populate_list(Number - 1). | |
go() -> lists:sum(populate_list(999)). |
This file contains hidden or 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(zomg). | |
-export([fac/1]). | |
-export([fib/1]). | |
% This is a simple function for calculate a factorial of a number. | |
fac(0) -> 1; | |
fac(Number) -> Number * fac(Number - 1). | |
% This is another simple one to calcula te the fibonacci sequence | |
fib(0) -> 0; | |
fib(1) -> 1; | |
fib(Number) -> fib(Number -1) + fib(Number - 2). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you write "money denomination" code in erlang Language ?