#!/usr/bin/python3
##Ziegenproblem :)
##Haben sie eine Ziege? Dann haben sie ein Problem!
##So.
## Bla, code by fabian zimmer & bastian greshake. released as cc by-nc 3.0

import random
import sys
import time
from multiprocessing import Process

def ziegen(x):
    doors = ["Z1","Z2","A"] #z = ziege, a = AUTO (was man halt so gewinnen will)
    doors = random.sample(doors,3)
    pick = random.sample(doors,1)
    #print(doors,pick)
    
    if pick[0] == "Z1":
        doors.remove("Z2")
        #print("Removed Z2")
    
    if pick[0] == "Z2":
        doors.remove("Z1")
        #print("Removed Z1")
    
    if pick[0] == "A":
        goats = ["Z1","Z2"]
        goats = random.sample(goats,1)
        doors.remove(goats[0])
        #print("Car chosen, removed",goats[0])
    
    if x == 0:
        if pick[0] == "A":
            return 1
        else:
            return 0
    else:
        if pick[0] != "A":
            return 1
        else:
            return 0

#print(ziegen(0))
input = int(sys.argv[1])

anfang = time.time()


# define a method for $input tries with changing the doors

def with_change(inputc):
	change = 0
	for i in range(inputc):
		change = change + ziegen(1)
	print("If the user changed the door he got the car in",change*100/input," % of all ",input," tries")
	
	
# define a method for $ input tries without changing the doors

def without_change(inputn):
	no_change = 0
	for i in range(inputn):
 		no_change = no_change + ziegen(0)
	print("If the user did not change the door he got the car in",no_change*100/input," % of all ",input," tries")
	

# here starts the black multiprocessing-voodoo

if __name__ == "__main__":			# i got no clue why you should need this thing
	pchange = Process(target=with_change, args=(input,))	# define process with change
	pnochange = Process(target=without_change, args=(input,)) # define process without change
	pchange.start()			# drivers start your engines!
	pnochange.start()
	pchange.join()			# u, dunno?
	pnochange.join()
	
ende = time.time()

print("Time:",ende-anfang)
#print("If user changed door:",change*100/input)
#print("If user does not change door:",no_change*100/input)

