Created
July 15, 2017 09:40
-
-
Save mikoim/3d32a0a2961a2bac27e78291727ecc41 to your computer and use it in GitHub Desktop.
Why does IO.puts print text so slow?
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 Catalan do | |
def main(argv) do | |
List.first(argv) | |
|> Integer.parse | |
|> (&elem(&1, 0)).() | |
|> parents | |
end | |
def parents(n), do: _parens("", n, n) | |
def _parens(prefix, left, right) do | |
unless left == 0 or right == 0 do | |
IO.puts prefix | |
end | |
if left > 0 do | |
_parens(prefix <> "(", left - 1, right) | |
end | |
if right > left do | |
_parens(prefix <> ")", left, right - 1) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment