MCPcopy Create free account
hub / github.com/AxlLind/AdventOfCode / parse

Method parse

2018/src/24.py:19–29  ·  view source on GitHub ↗
(s: str)

Source from the content-addressed store, hash-verified

17
18 @staticmethod
19 def parse(s: str) -> 'Unit':
20 units, hp, resistances, dmg, dmgtype, initiative = re.findall(PARSE_REGEX, s)[0]
21 weaknesses, immunities = set(), set()
22 if resistances:
23 for s in resistances[2:-1].split(';'):
24 t, _, *types = [w.rstrip(',') for w in s.strip().split(' ')]
25 if t == "weak":
26 weaknesses = set(types)
27 if t == "immune":
28 immunities = set(types)
29 return Unit(int(units), int(hp), int(dmg), dmgtype, int(initiative), weaknesses, immunities)
30
31 def effective_power(self) -> int:
32 return self.units * self.dmg

Callers 15

extract_timeFunction · 0.80
is_valid_passportFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
part_twoFunction · 0.80
extract_timeFunction · 0.80
parse_rangeFunction · 0.80

Calls 1

UnitClass · 0.85

Tested by

no test coverage detected