Simulate a game of Craps
Ruby 164
Pretty straightforward. Interesting features:
The crapping out cases are summarised as r%12<4
and the remaining natural cases are summarised as r%4==3
.
The initial string is stored in c
and further rolls are taken only if this is later alphabetically than the single letter ?P
(which only occurs for Point
.)
f=->{rand(6)+rand(6)+2}
s=0
r=f[]
print c=r%12<4?'Crapping out':r%4==3?'Natural':'Point',": #{r}
"
c>?P&&(until s==r||s==7
p s=f[]end
print s==7?"Don't ":"","Pass")
Python 3, 190 bytes
from random import*
r=randrange
p=print
a=r(5)+r(5)+2
c=890145//3**a%3
p(['Point:','Crapping out:','Natural:'][c],a)
if c<1:
while 7!=c!=a:c=r(5)+r(5)+2;p(c)
p(['Pass',"Don't pass"][c==7])
This is based on Celeo's answer; I replaced some lengthy conditionals with a magic number that encodes a LUT for each number, reused a variable, and did a few other miscellaneous golfs. Still room to golf; it's probably possible to get under 170.
I didn't try to use Python 2, so I don't know if it would be shorter.
Python 2, 226 224 bytes
First pass and there's a lot of code there:
from random import*
r=randrange
a=r(5)+r(5)+2
if a in[7,11]:print'Natural:',a
elif a in[2,3,12]:print'Crapping out:',a
else:
print'Point:',a
b=0
while b not in[7,a]:b=r(5)+r(5)+2;print b
print'Pass'if b-7else"Don't pass"
Thanks to Mego for 2 bytes!