Created
March 25, 2015 10:12
-
-
Save Svetixbot/dfbfb2cc8f13528d2da3 to your computer and use it in GitHub Desktop.
Win the Bandid Game! https://github.com/andyzeng1980/Data_Science_Workshop/tree/master/1-intro
This file contains hidden or 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 operator | |
from BanditGame import BanditGame | |
ba = BanditGame() | |
results = {} | |
for arm in range(1, 6): | |
results[arm] = 0 | |
for game in range(20): | |
startValue = ba.money() | |
ba.play(arm) | |
results[arm] = results[arm] + ba.money()-startValue #how much money you'll gane with this arm | |
bestArm = max(results.iteritems(), key=operator.itemgetter(1))[0] | |
while ba._money_check: | |
ba.play(bestArm) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment