Пример #1
0
def test_parse_2():
    replacements, molecule = parse_input(test_input_2)
    assert len(replacements) == 3
    assert replacements[0] == ('H', 'HO')
    assert replacements[1] == ('H', 'OH')
    assert replacements[2] == ('O', 'HH')
    assert molecule == 'HOHOHO'
Пример #2
0
def test_replacements_1():
    replacements, molecule = parse_input(test_input_1)
    generated_molecules = do_replacements(molecule, replacements)
    assert len(generated_molecules) == 4
    assert 'HOOH' in generated_molecules
    assert 'HOHO' in generated_molecules
    assert 'OHOH' in generated_molecules
    assert 'HHHH' in generated_molecules
Пример #3
0
def test_build_2_greedy():
    replacements, _ = parse_input(build_replacements)
    n_steps = build_molecule(replacements, 'HOHOHO', reverse=True, greedy=True)
    assert n_steps == 6
Пример #4
0
def test_build_1_reverse():
    replacements, _ = parse_input(build_replacements)
    n_steps = build_molecule(replacements, 'HOH', reverse=True)
    assert n_steps == 3
Пример #5
0
def test_build_2():
    replacements, _ = parse_input(build_replacements)
    n_steps = build_molecule(replacements, 'HOHOHO')
    assert n_steps == 6
Пример #6
0
def test_part_1():
    with open('input.txt') as f:
        specs = f.read()
    replacements, molecule = parse_input(specs)
    generated_molecules = do_replacements(molecule, replacements)
    assert len(generated_molecules) == 535
Пример #7
0
def test_replacements_2():
    replacements, molecule = parse_input(test_input_2)
    generated_molecules = do_replacements(molecule, replacements)
    assert len(generated_molecules) == 7
Пример #8
0
def test_part_2():
    with open('input.txt') as f:
        specs = f.read()
    replacements, molecule = parse_input(specs)
    n_steps = build_molecule(replacements, target=molecule, reverse=True, greedy=True)
    assert n_steps == 212