-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoads.py
More file actions
57 lines (46 loc) · 1.4 KB
/
toads.py
File metadata and controls
57 lines (46 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import random
def getPopulation(n):
array=[]
for i in range(num):
array.append(bool(random.randint(0, 1)))
random.shuffle(array)
return array
def TruthFulToadsA(population):
lst=[]
for i in range(len(population)):
if(population[i]==1):
population[i]="Trustworthy"
else:
population[i]="Tricky"
for i in range(len(population)):
if(population[i] == "Trustworthy"):
lst.append(i)
return lst
def TruthFulToadsB(population):
lst1=[]
arr=[]
for i in range(len(population)//2):
lst1.append(random.randint(1,1))
for j in range(len(population)//2):
lst1.append(random.randint(0,1))
random.shuffle(lst1)
for m in range(len(population)):
if(population[m]==1):
arr.append(lst1[i])
else:
ran=random.random()
if(ran<0.5):
arr.append(1)
else:
arr.append(0)
lst2=[]
for m in range(len(arr)):
if(arr[m] == 1):
lst2.append(m)
return lst2
num=int(input("Enter population : "))
population=getPopulation(num)
pop=TruthFulToadsA(population)
pop1=TruthFulToadsB(population)
print('Tode A say {} speak true'.format(pop))
print('Tode B say {} speak true'.format(pop1))