Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re^2: Dungeons and Dragons die roller (Golf)

by Anonymous Monk
on Nov 04, 2016 at 18:51 UTC ( #1175324=note: print w/replies, xml ) Need Help??

in reply to Re: Dungeons and Dragons die roller (Golf)
in thread Dungeons and Dragons die roller (Golf)

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?
  • Comment on Re^2: Dungeons and Dragons die roller (Golf)

Replies are listed 'Best First'.
Re^3: Dungeons and Dragons die roller (Golf)
by tybalt89 (Priest) on Nov 05, 2016 at 02:30 UTC

    ~~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 =?????
        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 2+int(rand(4))+d+int(rand(4))+d4+10 # or looking at each term 2 # since rand return 0..N-1 instead on 1..N, we add one f +or every die +int(rand(4)) # int in 0..3 +d # 0 +int(rand(4)) # int in 0..3 +d4 # also 0, the 'd' are here to help ignore the 4 +10 # desired extra # then eval that :)

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2018-05-21 11:34 GMT
Find Nodes?
    Voting Booth?