Skip to content

Instantly share code, notes, and snippets.

@ThomasParistech
Created January 15, 2022 09:21
Show Gist options
  • Save ThomasParistech/74cdca21014ba778c58235b41e6aa44b to your computer and use it in GitHub Desktop.
Save ThomasParistech/74cdca21014ba778c58235b41e6aa44b to your computer and use it in GitHub Desktop.
Secret santa _refine_possible_recipients
from typing import List
from players_info import ListOfPlayerInfo
def _refine_possible_recipients(possible_ids: List[List[int]]) -> List[List[int]]:
"""
Find players with a single possible recipient
and remove this recipient from the possibilities of the other players
"""
known_players = [idx for idx, list_ids in enumerate(possible_ids)
if len(list_ids) == 1]
while len(known_players) != 0:
known_idx = known_players.pop()
recipient_idx = possible_ids[known_idx][0]
for idx, list_ids in enumerate(possible_ids):
if idx != known_idx and recipient_idx in list_ids:
list_ids.remove(recipient_idx)
if len(list_ids) == 1:
known_players.append(idx)
return possible_ids
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment