Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- import itertools
- people = list(range(1, 11))
- colors = ['G', 'R', 'B']
- statements = [
- (1, 2, 'R'),
- (1, 7, 'G'),
- (2, 1, 'R'),
- (2, 3, 'R'),
- (3, 4, 'G'),
- (4, 3, 'R'),
- (4, 5, 'B'),
- (4, 7, 'B'),
- (5, 4, 'B'),
- (6, 7, 'B'),
- (7, 6, 'G'),
- (7, 8, 'B'),
- (8, 4, 'B'),
- (9, 4, 'G'),
- (9, 10, 'R'),
- (10, 1, 'B'),
- (10, 5, 'B'),
- (10, 7, 'G'),
- ]
- def is_true(speaker, target, claimed, assignment):
- sp = assignment[speaker]
- tg = assignment[target]
- fact = (tg == claimed)
- if sp == 'G':
- return fact
- if sp == 'R':
- return not fact
- return fact if claimed == 'R' else not fact
- def find_colors():
- for prod in itertools.product(colors, repeat=10):
- assignment = {i+1: prod[i] for i in range(10)}
- if all(is_true(s, t, c, assignment) for s, t, c in statements):
- return assignment
- return None
- if __name__ == '__main__':
- result = find_colors()
- if not result:
- print("Нет решения")
- else:
- mapping = {'G':'Зелёный','R':'Красный','B':'Синий'}
- for i in people:
- print(f"{i}: {mapping[result[i]]}")
Advertisement
Add Comment
Please, Sign In to add comment