codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
def diceroll(str) wstr = str.split(//) a = 0 tempa = "" b = 0 tempb = "" c = 0 if wstr[0] == "d" a = 1 else for i in wstr if i != "d" tempa = tempa.concat(i) elsif i == "d" break end end a = tempa.to_i end for i in 0..wstr.length-1 if wstr[i] == "+" or wstr[i] == "-" b = (wstr[i+1,wstr.length-1].join).to_i break end end tempina = 0 tempinb = 0 for i in 0..wstr.length-1 if wstr[i] == "d" tempina = i elsif wstr[i] == "+" or wstr[i] == "-" tempinb = i end end c = ((wstr[tempina+1,tempinb-1]).join).to_i retnum = 0 while retnum < a retnum = rand(b) end for i in 0..wstr.length-1 if wstr[i] == "+" retnum = retnum + c elsif wstr[i] == "-" retnum = retnum - c end end retnum end puts diceroll("d34-15") puts diceroll("4d45+26")
Private
[
?
]
Run code
Submit