Skip to content

Instantly share code, notes, and snippets.

@ceidsmoe
Created Feb 6, 2019
Embed
What would you like to do?
Riddler Classic 2/1/2019
import numpy as np
def war(h1, h2):
h1_wins = 0
h2_wins = 0
for c1, c2 in zip(h1, h2):
if c1 > c2:
h1_wins += 1
else:
h2_wins += 1
if h1_wins == 5:
return 0
elif h2_wins == 5:
return 1
def hand_setup():
red = [14]*4 + [9]*4 + [7]*4
blue = [13]*4 + [11]*4 + [6]*4
black = [12]*4 + [10]*4 + [8]*4
hands = [red, blue, black]
for h in hands:
np.random.shuffle(h)
return hands
def endless_war():
redvblue = [0,0]
redvblack = [0,0]
bluevblack = [0,0]
for i in xrange(1000000):
red, blue, black = hand_setup()
redvblue[war(red, blue)] += 1
redvblack[war(red, black)] += 1
bluevblack[war(blue, black)] += 1
print "Red v. Blue: " + str(redvblue)
print "Red v. Black: " + str(redvblack)
print "Blue v. Black: " + str(bluevblack)
endless_war()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment