def part2(text): def starred(func): def wrapper(record): return func(**dict(field.split(":") for field in record.split())) return wrapper def height(hgt): if hgt.endswith("cm"): return 150 <= int(hgt.removesuffix("cm")) <= 193 elif hgt.endswith("in"): return 59 <= int(hgt.removesuffix("in")) <= 76 @starred def valid(byr=0, iyr=0, eyr=0, hgt="", hcl="", ecl="", pid="", cid=None): if not 1920 <= int(byr) <= 2002: return False elif not 2010 <= int(iyr) <= 2020: return False elif not 2020 <= int(eyr) <= 2030: return False elif not height(hgt): return False elif not re.match(r"#[0-9a-f]{6}", hcl): return False elif ecl not in ECL: return False elif not len(pid) == 9 or not pid.isdecimal(): return False return True return count_items(text.split("\n\n"), valid)
def valid(string): if 8 in string or 11 in string or 14 in string: return False if not any(starmap(straight, successive(string, 3))): return False pairs = unique_everseen(starfilter(eq, successive(string))) return 1 < count_items(pairs)
def test_count_failure5(): # eq True but no pred with pytest.raises(TypeError): count_items([T(0)], eq=True)
def test_count_failure4(): # Too few arguments with pytest.raises(TypeError): count_items()
def test_count_failure3(): # Regression test when accessing the next item of the iterable resulted # in an Exception. For example when the iterable was a filter and the # filter function threw an exception. with pytest.raises(_hf.FailNext.EXC_TYP, match=_hf.FailNext.EXC_MSG): count_items(_hf.FailNext())
def count(a_gen, b_gen, sample): def valid(a, b): return a & BITS == b & BITS return count_items(islice(zip(a_gen, b_gen), sample), packed(valid))
def part1(text): def valid(record): return FIELDS.issubset(field.split(":")[0] for field in record.split()) return count_items(text.split("\n\n"), valid)
def test_count_failure8(): # Changing next method with pytest.raises(_hf.CacheNext.EXC_TYP, match=_hf.CacheNext.EXC_MSG): count_items(_hf.CacheNext(1))
def test_count_normal5(): assert count_items([T(1), T(2), T(3)], lambda x: x > T(2)) == 1
def test_count_normal4(): assert count_items([], iteration_utilities.return_identity) == 0
def test_count_normal3(): # None as pred is equal to not giving any predicate assert count_items([T(0), T(0), T(1), T(1)], None) == 4
def test_count_normal2(): assert count_items([T(0), T(0), T(1)], bool) == 1
def test_count_normal1(): assert count_items([T(0), T(0)]) == 2
def test_count_empty1(): assert count_items([]) == 0
def test_count_failure6(): # eq True but pred None (like not given) with pytest.raises(TypeError): count_items([T(0)], pred=None, eq=True)
def test_count_failure7(): # function returns item without boolean interpretation with pytest.raises(_hf.FailBool.EXC_TYP, match=_hf.FailBool.EXC_MSG): count_items([T(0)], lambda x: _hf.FailBool())
def test_count_normal6(): assert count_items([T(1), T(2), T(3)], lambda x: x < T(3)) == 2
def part2(text): graph, node = process(text) unique = partial(ne, node) return count_items(takewhile(unique, applyfunc(graph.get, node))) + 1
def test_count_normal7(): assert count_items([T(3), T(1), T(2), T(3), T(3)], T(3), True) == 3
def test_count_failure1(): with pytest.raises(_hf.FailIter.EXC_TYP, match=_hf.FailIter.EXC_MSG): count_items(_hf.FailIter())
def test_count_failure2(): with pytest.raises(TypeError): count_items([T(1)], T(1))
def valid_combo(k): return count_items(combinations(nums, k), target_sum)
def part1(text, group="0"): parent, find = unite(text) return count_items(map(find, parent.values()), find(group), True)