Skip to content

Instantly share code, notes, and snippets.

@jordancluts
Created October 3, 2019 20:31
Show Gist options
  • Save jordancluts/f98a48ec08915ed639b1148cf06ae19d to your computer and use it in GitHub Desktop.
Save jordancluts/f98a48ec08915ed639b1148cf06ae19d to your computer and use it in GitHub Desktop.
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