2012-02-20 04:34:17 +01:00
|
|
|
# Created by Lukeroge, improved by TheNoodle
|
2011-11-20 10:23:31 +01:00
|
|
|
from util import hook
|
2012-04-23 03:16:08 +02:00
|
|
|
from random import getrandbits
|
2011-11-20 10:23:31 +01:00
|
|
|
|
2012-02-29 06:47:11 +01:00
|
|
|
|
2012-04-23 03:29:25 +02:00
|
|
|
# yay for cryptic but fast code
|
2011-12-01 17:13:08 +01:00
|
|
|
def flip_simple(count):
|
2012-04-23 03:16:08 +02:00
|
|
|
heads, tails = 0, 0
|
|
|
|
for x in xrange(count):
|
2012-04-23 03:29:25 +02:00
|
|
|
if not getrandbits(1):
|
2011-12-02 14:42:36 +01:00
|
|
|
heads += 1
|
2011-12-01 17:13:08 +01:00
|
|
|
else:
|
2011-12-02 14:42:36 +01:00
|
|
|
tails += 1
|
2012-05-09 03:26:52 +02:00
|
|
|
return heads, tails
|
2011-12-02 14:42:36 +01:00
|
|
|
|
2011-11-20 10:23:31 +01:00
|
|
|
|
2011-12-01 17:13:08 +01:00
|
|
|
@hook.command(autohelp=False)
|
|
|
|
def coin(inp):
|
2012-05-16 05:07:27 +02:00
|
|
|
"coin [amount] -- Flips [amount] of coins."
|
2012-02-29 06:47:11 +01:00
|
|
|
# checking for valid input. if valid input [count=inp],
|
|
|
|
# if invalid [return error], if no input [count=1]
|
2011-12-01 17:13:08 +01:00
|
|
|
if inp.isdigit():
|
|
|
|
count = int(inp)
|
|
|
|
else:
|
|
|
|
if inp:
|
2012-02-17 01:46:09 +01:00
|
|
|
return "Invalid input."
|
2011-12-01 17:13:08 +01:00
|
|
|
else:
|
|
|
|
count = 1
|
2012-02-17 01:46:09 +01:00
|
|
|
|
2012-04-23 02:54:00 +02:00
|
|
|
if count > 9001:
|
|
|
|
return "Too many coins! Maximum is 9001."
|
2012-05-09 03:30:50 +02:00
|
|
|
elif count == 1:
|
2012-04-23 03:16:08 +02:00
|
|
|
flip = getrandbits(1)
|
2011-12-01 17:13:08 +01:00
|
|
|
if flip == 1:
|
2012-04-23 03:16:08 +02:00
|
|
|
return "You flip a coin and get heads."
|
2011-12-01 17:13:08 +01:00
|
|
|
else:
|
2012-04-23 03:16:08 +02:00
|
|
|
return "You flip a coin and get tails."
|
2012-05-09 03:30:50 +02:00
|
|
|
elif count == 0:
|
|
|
|
return "You make a coin flipping motion with your hands."
|
2011-12-01 17:13:08 +01:00
|
|
|
else:
|
2011-12-02 14:42:36 +01:00
|
|
|
flips = flip_simple(count)
|
2012-04-23 03:16:08 +02:00
|
|
|
return "You flip %i coins and get " \
|
|
|
|
"%i heads and %i tails." % (count, flips[0], flips[1])
|