Created
February 6, 2019 00:33
-
-
Save geidsmoe/31bf0f60bf18dd5387ee3a81ba204cd5 to your computer and use it in GitHub Desktop.
Riddler Classic 2/1/2019
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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