Created
April 4, 2014 08:22
-
-
Save sandinist/9970365 to your computer and use it in GitHub Desktop.
るびまのElrangサンプルコードにあがっていたmodule(fibcalc)をElixirにしてみた(等価ではない) http://magazine.rubyist.net/?0017-Legwork
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
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