{"record":{"id":"31e92c9922422617","repo":"TheAlgorithms/Python","slug":"parameters-chain-length-and-number-limit-must-be-g","errorCode":null,"errorMessage":"Parameters chain_length and number_limit must be greater than 0","messagePattern":"Parameters chain_length and number_limit must be greater than 0","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"project_euler/problem_074/sol2.py","lineNumber":105,"sourceCode":"    >>> solution(0, 1000)\n    Traceback (most recent call last):\n        ...\n    ValueError: Parameters chain_length and number_limit must be greater than 0\n\n    >>> solution(10, 0)\n    Traceback (most recent call last):\n        ...\n    ValueError: Parameters chain_length and number_limit must be greater than 0\n\n    >>> solution(10, 1000)\n    26\n    \"\"\"\n\n    if not isinstance(chain_length, int) or not isinstance(number_limit, int):\n        raise TypeError(\"Parameters chain_length and number_limit must be int\")\n\n    if chain_length <= 0 or number_limit <= 0:\n        raise ValueError(\n            \"Parameters chain_length and number_limit must be greater than 0\"\n        )\n\n    # the counter for the chains with the exact desired length\n    chains_counter = 0\n    # the cached sizes of the previous chains\n    chain_sets_lengths: dict[int, int] = {}\n\n    for start_chain_element in range(1, number_limit):\n        # The temporary set will contain the elements of the chain\n        chain_set = set()\n        chain_set_length = 0\n\n        # Stop computing the chain when you find a cached size, a repeating item or the\n        # length is greater then the desired one.\n        chain_element = start_chain_element\n        while (\n            chain_element not in chain_sets_lengths","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/project_euler/problem_074/sol2.py#L87-L123","documentation":"Raised by solution() in project_euler/problem_074/sol2.py when chain_length <= 0 or number_limit <= 0. A non-positive chain length makes 'exactly chain_length non-repeating elements' undefined, and number_limit <= 0 leaves the search range range(1, number_limit) empty; both are rejected with ValueError after the isinstance guard.","triggerScenarios":"solution(0, 1000), solution(60, 0), solution(-1, -1), or a computed number_limit that collapses to 0 (e.g. limit - offset with offset >= limit).","commonSituations":"Config-driven thresholds defaulting to 0; sweeps that include edge values; arithmetic on limits producing 0 or negatives.","solutions":["Pass both parameters > 0: solution(60, 1000000) for the canonical problem.","Validate config before calling: if chain_length <= 0 or number_limit <= 0: raise.","Fix the upstream computation that zeroed number_limit."],"exampleFix":"# before\nnumber_limit = upper - lower  # 0 when lower >= upper\nresult = solution(60, number_limit)\n\n# after\nif number_limit <= 0:\n    raise ValueError(f\"number_limit must be > 0, got {number_limit}\")\nresult = solution(60, number_limit)","handlingStrategy":"validation","validationCode":"if chain_length <= 0 or number_limit <= 0:\n    raise ValueError(\n        f\"need chain_length > 0 and number_limit > 0, \"\n        f\"got {chain_length}, {number_limit}\"\n    )\nsolution(chain_length, number_limit)","typeGuard":"def are_positive_ints(*values) -> bool:\n    return all(isinstance(v, int) and v > 0 for v in values)","tryCatchPattern":"try:\n    result = solution(chain_length, number_limit)\nexcept ValueError as e:\n    if \"greater than 0\" in str(e):\n        raise ConfigError(f\"invalid euler-74 params: {e}\") from e\n    raise","preventionTips":["Reject zero defaults in config before the call.","Validate both parameters together, matching the library's combined check.","Use canonical values solution(60, 1000000) unless experimenting."],"tags":["project-euler","validation","valueerror","input-validation"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}