Last active
January 19, 2017 20:56
-
-
Save gausby/29716572b113dbdbec63a0abdd8bb88b to your computer and use it in GitHub Desktop.
Probably not the best we can come up with!
This file contains hidden or 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 Dice do | |
@moduledoc """ | |
The best I could come up with... | |
iex> import Dice | |
...> ~d'1d6'+3 | |
""" | |
def sigil_d(input, []) do | |
[n, eyes] = | |
String.split(input, "d", parts: 2) | |
|> Enum.map(&String.to_integer/1) | |
# Baby needs a new pair of shoes! | |
Stream.repeatedly(fn -> :rand.uniform(eyes) end) | |
|> Enum.take(n) | |
|> Enum.sum() | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment