Created
October 3, 2019 20:31
-
-
Save jordancluts/f98a48ec08915ed639b1148cf06ae19d to your computer and use it in GitHub Desktop.
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
function roll(roll) | |
m=match(r"(?<number>\d*)[dD](?<sides>\d+)", roll) | |
m["number"] == "" ? number = 1 : number=parse(Int,m["number"]) | |
sides=parse(Int,m["sides"]) | |
roll_dice(number,sides) | |
end | |
function roll_dice(number::Integer,sides::Integer) | |
sum([rand(1:sides) for _ in 1:number]) | |
end | |
macro roll_str(roll_string) | |
roll(roll_string) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment