1from typing import Dict, List
2
3
4class RunewordsCalculator:
5
6 def __init__(self, runewords : Dict[str, List[str]]):
7 self._runewords : Dict[str, List[str]] = runewords
8 self._acc_runes : List[str] = []
9 self._runeword_names = list(runewords.keys())
10
11 def add_runes(self, runes : List[str]):
12 self._acc_runes.extend(runes)
13
14 def __iter__(self):
15 return self
16
17 def __next__(self):
18 if not self._runeword_names:
19 raise StopIteration
20 for name in self._runeword_names:
21 recipe = self._runewords[name]
22 it = iter(self._acc_runes)
23 if all(rune in it for rune in recipe):
24 self._runeword_names.remove(name)
25 return name
26 return None
.......
----------------------------------------------------------------------
Ran 7 tests in 0.000s
OK