Evaluate dice rolling notation strings

前端 未结 14 1632
甜味超标
甜味超标 2021-01-30 14:55

Rules

Write a function that accepts string as a parameter, returning evaluated value of expression in dice notation, including addition and multiplication.

To

14条回答
  •  不要未来只要你来
    2021-01-30 15:27

    J

    With cobbal's help, squeeze everything into 93 characters.

    $ jconsole
       e=:".@([`('%'"_)@.(=&'/')"0@,)@:(3 :'":(1".r{.y)([:+/>:@?@$) ::(y&[)0".}.y}.~r=.y i.''d'''@>)@;:
    
       e '3d6 + 12'
    20
       e 10$,:'3d6 + 12'
    19 23 20 26 24 20 20 20 24 27
       e 10$,:'4*d12 + 3'
    28 52 56 16 52 52 52 36 44 56
       e 10$,:'d100'
    51 51 79 58 22 47 95 6 5 64
    

提交回复
热议问题