{"record":{"id":"bf86ecc0ef7399ef","repo":"TheAlgorithms/Python","slug":"open-knight-tour-cannot-be-performed-on-a-board-of","errorCode":null,"errorMessage":"Open Knight Tour cannot be performed on a board of size {n}","messagePattern":"Open Knight Tour cannot be performed on a board of size (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"backtracking/knight_tour.py","lineNumber":95,"sourceCode":"    [[1]]\n\n    >>> open_knight_tour(2)\n    Traceback (most recent call last):\n        ...\n    ValueError: Open Knight Tour cannot be performed on a board of size 2\n    \"\"\"\n\n    board = [[0 for i in range(n)] for j in range(n)]\n\n    for i in range(n):\n        for j in range(n):\n            board[i][j] = 1\n            if open_knight_tour_helper(board, (i, j), 1):\n                return board\n            board[i][j] = 0\n\n    msg = f\"Open Knight Tour cannot be performed on a board of size {n}\"\n    raise ValueError(msg)\n\n\nif __name__ == \"__main__\":\n    import doctest\n\n    doctest.testmod()\n","sourceCodeStart":77,"sourceCodeEnd":102,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/backtracking/knight_tour.py#L77-L102","documentation":"Raised by casimir_force() in physics/casimir_effect.py when the distance (plate separation) argument is negative. Plate separation enters the formula as distance**4, so a sign is meaningless there; the library rejects negative separations outright. The check fires after the force check, before the area check.","triggerScenarios":"casimir_force(force=3457e-12, area=0, distance=-0.00344); passing a displacement relative to a reference point that can be negative on one side.","commonSituations":"Distance measured as a signed offset from an origin (e.g. interferometer zero position) rather than an absolute plate separation; unit-conversion code that flips sign.","solutions":["Pass the absolute plate separation: abs(distance) when the sign is only positional.","Validate distance > 0 in your data pipeline before calling.","Catch ValueError and reject the offending record if parsing external measurements."],"exampleFix":"# before\ncasimir_force(force=3e-12, area=0, distance=gap_offset)  # gap_offset = -0.00344\n\n# after\ncasimir_force(force=3e-12, area=0, distance=abs(gap_offset))","handlingStrategy":"validation","validationCode":"if distance < 0:\n    raise ValueError(f\"plate separation must be >= 0, got {distance}\")\ncasimir_force(force=f, area=a, distance=distance)","typeGuard":null,"tryCatchPattern":"try:\n    casimir_force(force=f, area=a, distance=d)\nexcept ValueError as e:\n    if \"Distance\" in str(e):\n        casimir_force(force=f, area=a, distance=abs(d))\n    else:\n        raise","preventionTips":["Store absolute plate separation, not signed offsets, in experiment data.","Check distance sign before the call; it is checked second, after force.","Zero distance also fails the one-zero rule if passed as the unknown with another 0."],"tags":["physics","input-validation","sign-convention"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}