Last active
March 21, 2017 11:33
-
-
Save wmalarski/c6358a5ab37b1d7e03fbd3b77f8be999 to your computer and use it in GitHub Desktop.
Python lab2
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
from __future__ import division | |
import random | |
l = [0, 1, 2] | |
def generate_choice(): | |
choice = random.choice(l) | |
cross = random.choice(l) | |
show = random.choice(list(set(l) - {choice, cross})) | |
return choice, cross, show | |
def generate_choice_list(n): | |
return [generate_choice() for i in range(n)] | |
def calc_no_change(n): | |
def red(cnt, (choice, cross, _)): | |
return (cnt + 1) if choice == cross else cnt | |
return reduce(red, generate_choice_list(n), 0)/n | |
def calc_change(n): | |
def red(cnt, (choice, cross, show)): | |
choice = (set(l) - {choice, show}).pop() | |
return (cnt + 1) if choice == cross else cnt | |
return reduce(red, generate_choice_list(n), 0)/n | |
print calc_no_change(1000) | |
print calc_change(1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment