Skip to content

Instantly share code, notes, and snippets.

@sandinist
Created April 4, 2014 08:22
Show Gist options
  • Save sandinist/9970365 to your computer and use it in GitHub Desktop.
Save sandinist/9970365 to your computer and use it in GitHub Desktop.
るびまのElrangサンプルコードにあがっていたmodule(fibcalc)をElixirにしてみた(等価ではない) http://magazine.rubyist.net/?0017-Legwork
defmodule Fibcalc do
def calc_fibs(list) do
list
|>
Enum.map(fn (elem) ->
spawn fn -> IO.puts "fib(#{elem}) = #{Fibcalc.fib(elem)}" end
end)
end
def fib(0), do: 1
def fib(1), do: 1
def fib(n) do
fib(n-1) + fib(n-2)
end
end
Fibcalc.calc_fibs([12, 3, 11, 4, 24, 31, 28, 10])
receive do
after 1000 -> nil
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment