Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Dungeons and Dragons die roller (Golf)

by Grimy (Pilgrim)
on Oct 25, 2016 at 16:06 UTC ( #1174699=note: print w/replies, xml ) Need Help??

in reply to Dungeons and Dragons die roller (Golf)

Straightforward 39 bytes (37 + 2 flags) solution :
#!perl -pl /\d+\+/;$-+=rand$&for 1..$_;$_+=$'+$-
More complex 35 bytes solution :
#!perl -pl s/d/q(+~~rand($')+d)x$`/e;$_=eval
Due to the use of $', they canít easily be ran from the command-line. Just store them in a file.

Replies are listed 'Best First'.
Re^2: Dungeons and Dragons die roller (Golf)
by Anonymous Monk on Nov 04, 2016 at 18:51 UTC
    After staring at this for a while, I'm not sure how exactly this works (mainly, what does +~~ do?). Would it be possible to explain how the 35 bytes solution works?

      ~~rand($') is the same as int(rand($'))

        I may be missing something very obvious, but could someone step through this one step at a time? The way I'm reading it, something like the below happens, and it doesn't make much sense to me.
        Input: 2d4+10 Code: s/d/q(+~~rand($')+d)x$`/e; 2d4+10 2(q(+~~rand($')+d)x$`)4+10 2(q(+int(rand($'))+d)x$`)4+10 2(q(+int(rand(4+10))+d)x2)4+10 2('+int(rand(4+10))+d'x2)4+10 2('+int(rand(4+10))+d''+int(rand(4+10))+d')4+10 =?????

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1174699]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2017-10-21 00:19 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (268 votes). Check out past polls.