Skip to content

Instantly share code, notes, and snippets.

@bltavares
Last active August 29, 2015 14:10
Show Gist options
  • Save bltavares/6984d49089e193a6181b to your computer and use it in GitHub Desktop.
Save bltavares/6984d49089e193a6181b to your computer and use it in GitHub Desktop.
defmodule Challenge do
def printer("", acc) do
acc
end
def printer("%%d" <> rest, acc) do
fn int ->
next = acc <> to_string(int)
printer(rest, next)
end
end
def printer("%%s" <> rest, acc) do
fn str ->
printer(rest, acc <> str)
end
end
def printer(expr, acc) do
[h| t] = String.codepoints(expr)
printer(to_string(t), acc <> h)
end
def printf(str) do
printer(str, "")
end
end
Challenge.printf("hello %%d %%s").(1).("world") |> IO.puts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment