repl.it
@EdgarOnghena/

INF TP 3.8.3

Python

No description

fork
loading
Files
  • main.py
main.py
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
import random

N = int(input("Nombre de personnes: "))

# List initialization
personnes = ["C" if x == 0 else "I" for x in range(N)]

def day() -> bool:
  # Random index selection
  x = random.randint(0, N - 1)
  y = random.randint(0, N - 2)
  if y >= x: y += 1
  
  # Value resolving
  xv = personnes[x]
  yv = personnes[y]

  xo, yo = sorted((xv, yv))
  if xo == yo == 'C': personnes[x] = personnes[y] = 'M'
  if xo == yo == 'M': personnes[x] = personnes[y] = 'M'

  if xo == 'C' and yo == 'M':
    personnes[x] = personnes[y] = 'M'
  if xo == 'C' and yo == 'I':
    personnes[x] = personnes[y] = 'C'

while 'C' in personnes:
  day()

print(personnes)
Fetching token
?