Created
December 16, 2018 11:19
-
-
Save E14/c2bd0df94524596c6365c5e1fab5d1bf to your computer and use it in GitHub Desktop.
Dailyprogrammer #367
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
# https://www.reddit.com/r/dailyprogrammer/comments/9cvo0f | |
defmodule Subfactorials do | |
def subfactorial(0), do: 1 | |
def subfactorial(1), do: 0 | |
def subfactorial(n), do: (n-1)*(subfactorial(n-1)+subfactorial(n-2)) | |
end | |
IO.stream(:stdio, :line)|>Enum.each( | |
&(&1|>String.trim|>String.to_integer|>Subfactorials.subfactorial|>IO.puts) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment