def transition(config, rules):
    """Get next state of cell for a rule (Wolfram code).

    :param config: Neighbor configuration.
    :param rules: Rule for state transistion.
    :returns: Next state.
    :raises ValueError: If config is invalid.
    """
    assert len(rules) == 8

    if config == [1, 1, 1]:
        return rules[0]
    elif config == [1, 1, 0]:
        return rules[1]
    elif config == [1, 0, 1]:
        return rules[2]
    elif config == [1, 0, 0]:
        return rules[3]
    elif config == [0, 1, 1]:
        return rules[4]
    elif config == [0, 1, 0]:
        return rules[5]
    elif config == [0, 0, 1]:
        return rules[6]
    elif config == [0, 0, 0]:
        return rules[7]

    raise ValueError(f"Invalid config argument: {config}")