Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Commonmark migration
Source Link

QBIC, 40 bytes

{[1,r|g=g+_r1,6|]~g=r*3.5|_X\g=0?r┘r=r+2

Thispretty much literally does what the challenge asks for; seems the shortest way to get the distribution right.

##Explanation

Explanation

{ DO infinitely
[1,r| FOR a=1, a<=r (at start, r == 2), a++
g=g+ Add to g (0 at start)
 _r1,6| a random number between 1 and 6 incl.
] NEXT
~g=r*3.5 IF the result of all dice rolls equals the expected value
|_X THEN quit
\g=0 ELSE, reset the dice total
?r┘ PRINT the number of dice used
r=r+2 and add 2 dice.
 END IF and LOOP are courtiously provided by QBIC at EOF.

QBIC, 40 bytes

{[1,r|g=g+_r1,6|]~g=r*3.5|_X\g=0?r┘r=r+2

Thispretty much literally does what the challenge asks for; seems the shortest way to get the distribution right.

##Explanation

{ DO infinitely
[1,r| FOR a=1, a<=r (at start, r == 2), a++
g=g+ Add to g (0 at start)
 _r1,6| a random number between 1 and 6 incl.
] NEXT
~g=r*3.5 IF the result of all dice rolls equals the expected value
|_X THEN quit
\g=0 ELSE, reset the dice total
?r┘ PRINT the number of dice used
r=r+2 and add 2 dice.
 END IF and LOOP are courtiously provided by QBIC at EOF.

QBIC, 40 bytes

{[1,r|g=g+_r1,6|]~g=r*3.5|_X\g=0?r┘r=r+2

Thispretty much literally does what the challenge asks for; seems the shortest way to get the distribution right.

Explanation

{ DO infinitely
[1,r| FOR a=1, a<=r (at start, r == 2), a++
g=g+ Add to g (0 at start)
 _r1,6| a random number between 1 and 6 incl.
] NEXT
~g=r*3.5 IF the result of all dice rolls equals the expected value
|_X THEN quit
\g=0 ELSE, reset the dice total
?r┘ PRINT the number of dice used
r=r+2 and add 2 dice.
 END IF and LOOP are courtiously provided by QBIC at EOF.
Source Link
steenbergh
  • 8.2k
  • 1
  • 27
  • 43

QBIC, 40 bytes

{[1,r|g=g+_r1,6|]~g=r*3.5|_X\g=0?r┘r=r+2

Thispretty much literally does what the challenge asks for; seems the shortest way to get the distribution right.

##Explanation

{ DO infinitely
[1,r| FOR a=1, a<=r (at start, r == 2), a++
g=g+ Add to g (0 at start)
 _r1,6| a random number between 1 and 6 incl.
] NEXT
~g=r*3.5 IF the result of all dice rolls equals the expected value
|_X THEN quit
\g=0 ELSE, reset the dice total
?r┘ PRINT the number of dice used
r=r+2 and add 2 dice.
 END IF and LOOP are courtiously provided by QBIC at EOF.

AltStyle によって変換されたページ (->オリジナル) /