Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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 (Monsignor) 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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1175324]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2023-12-05 20:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (27 votes). Check out past polls.

    Notices?