serikov

mini_ceo_16

Aug 6th, 2025
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.26 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3.  
  4. import itertools
  5.  
  6. people = list(range(1, 11))
  7. colors = ['G', 'R', 'B']
  8.  
  9. statements = [
  10.     (1, 2, 'R'),
  11.     (1, 7, 'G'),
  12.     (2, 1, 'R'),
  13.     (2, 3, 'R'),
  14.     (3, 4, 'G'),
  15.     (4, 3, 'R'),
  16.     (4, 5, 'B'),
  17.     (4, 7, 'B'),
  18.     (5, 4, 'B'),
  19.     (6, 7, 'B'),
  20.     (7, 6, 'G'),
  21.     (7, 8, 'B'),
  22.     (8, 4, 'B'),
  23.     (9, 4, 'G'),
  24.     (9, 10, 'R'),
  25.     (10, 1, 'B'),
  26.     (10, 5, 'B'),
  27.     (10, 7, 'G'),
  28. ]
  29.  
  30. def is_true(speaker, target, claimed, assignment):
  31.     sp = assignment[speaker]
  32.     tg = assignment[target]
  33.     fact = (tg == claimed)
  34.     if sp == 'G':
  35.         return fact
  36.     if sp == 'R':
  37.         return not fact
  38.     return fact if claimed == 'R' else not fact
  39.  
  40. def find_colors():
  41.     for prod in itertools.product(colors, repeat=10):
  42.         assignment = {i+1: prod[i] for i in range(10)}
  43.         if all(is_true(s, t, c, assignment) for s, t, c in statements):
  44.             return assignment
  45.     return None
  46.  
  47. if __name__ == '__main__':
  48.     result = find_colors()
  49.     if not result:
  50.         print("Нет решения")
  51.     else:
  52.         mapping = {'G':'Зелёный','R':'Красный','B':'Синий'}
  53.         for i in people:
  54.             print(f"{i}: {mapping[result[i]]}")
  55.  
Advertisement
Add Comment
Please, Sign In to add comment