Skip to content

Instantly share code, notes, and snippets.

@pedrosnk
Created June 25, 2012 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pedrosnk/2988194 to your computer and use it in GitHub Desktop.
Save pedrosnk/2988194 to your computer and use it in GitHub Desktop.
Learning Erlang
% 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)).
-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).
@tuafeeqahmed
Copy link

Can you write "money denomination" code in erlang Language ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment