{"record":{"id":"c89068267e5249ac","repo":"TheAlgorithms/Python","slug":"gon-side-must-be-in-the-range-3-5","errorCode":null,"errorMessage":"gon_side must be in the range [3, 5]","messagePattern":"gon_side must be in the range \\[3, 5\\]","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"project_euler/problem_068/sol1.py","lineNumber":64,"sourceCode":"def solution(gon_side: int = 5) -> int:\n    \"\"\"\n    Find the maximum number for a \"magic\" gon_side-gon ring\n\n    The gon_side parameter should be in the range [3, 5],\n    other side numbers aren't tested\n\n    >>> solution(3)\n    432621513\n    >>> solution(4)\n    426561813732\n    >>> solution()\n    6531031914842725\n    >>> solution(6)\n    Traceback (most recent call last):\n    ValueError: gon_side must be in the range [3, 5]\n    \"\"\"\n    if gon_side < 3 or gon_side > 5:\n        raise ValueError(\"gon_side must be in the range [3, 5]\")\n\n    # Since it's 16, we know 10 is on the outer ring\n    # Put the big numbers at the end so that they are never the first number\n    small_numbers = list(range(gon_side + 1, 0, -1))\n    big_numbers = list(range(gon_side + 2, gon_side * 2 + 1))\n\n    for perm in permutations(small_numbers + big_numbers):\n        numbers = generate_gon_ring(gon_side, list(perm))\n        if is_magic_gon(numbers):\n            return int(\"\".join(str(n) for n in numbers))\n\n    msg = f\"Magic {gon_side}-gon ring is impossible\"\n    raise ValueError(msg)\n\n\ndef generate_gon_ring(gon_side: int, perm: list[int]) -> list[int]:\n    \"\"\"\n    Generate a gon_side-gon ring from a permutation state","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/project_euler/problem_068/sol1.py#L46-L82","documentation":"Raised by solution() in project_euler/problem_068/sol1.py when gon_side is outside [3, 5]. The magic gon ring generator only handles 3-gon, 4-gon, and 5-gon rings because the digit-concatenation scheme and permutation search are sized for those; gon_side 6 or more would need numbers with two digits on the inner ring and explodes combinatorially.","triggerScenarios":"solution(2), solution(6), solution(10). Any loop over range(1, 11) that calls solution(gon_side) will raise for gon_side in {1, 2, 6, 7, 8, 9, 10}.","commonSituations":"Generalizing a parameter sweep beyond the supported domain; user-facing wrappers that expose gon_side without a range check; copying the pattern to 'support' 6-gon rings without rewriting the generator.","solutions":["Call only with 3, 4, or 5 (or no argument for the default 5).","Clamp or reject user input first: if not 3 <= gon_side <= 5: raise/reject in your wrapper.","If you need larger rings, write a dedicated generator; do not widen this guard."],"exampleFix":"# before\nfor gon_side in range(2, 8):\n    print(solution(gon_side))  # ValueError at 2 and again at 6\n\n# after\nfor gon_side in (3, 4, 5):\n    print(solution(gon_side))","handlingStrategy":"validation","validationCode":"if not (isinstance(gon_side, int) and 3 <= gon_side <= 5):\n    raise ValueError(f\"gon_side must be in [3, 5], got {gon_side!r}\")\nsolution(gon_side)","typeGuard":"def is_supported_gon_side(value) -> bool:\n    return isinstance(value, int) and 3 <= value <= 5","tryCatchPattern":"try:\n    result = solution(gon_side)\nexcept ValueError as e:\n    if \"range [3, 5]\" in str(e):\n        logger.error(\"unsupported gon_side %s; use 3-5\", gon_side)\n    else:\n        raise","preventionTips":["Restrict parameter sweeps to (3, 4, 5).","Constrain gon_side in your UI/config with min=3, max=5.","Do not widen the guard without rewriting the ring generator for bigger n."],"tags":["project-euler","validation","valueerror","domain-check"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}