Skip to content

Instantly share code, notes, and snippets.

@E14
Created December 16, 2018 11:19
Show Gist options
  • Save E14/c2bd0df94524596c6365c5e1fab5d1bf to your computer and use it in GitHub Desktop.
Save E14/c2bd0df94524596c6365c5e1fab5d1bf to your computer and use it in GitHub Desktop.
Dailyprogrammer #367
# 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