Created
June 26, 2025 09:31
-
-
Save sina-programer/7eb41480fc9b2e50075e968638a78464 to your computer and use it in GitHub Desktop.
project numbers in [a, b] as a cycle. (a-1 => b, b+1 => a)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def transform(x, a, b): | |
''' projects x in [a, b] like a cycle. a-1=>b, b+1=>a ''' | |
n = b - a + 1 | |
return (x - a) % n + a | |
if __name__ == "__main__": | |
a = 1 | |
b = 10 | |
assert all(map(lambda x: x == transform(x, a, b), range(a, b+1))) | |
assert transform(a-1, a, b) == b | |
assert transform(a-2, a, b) == b-1 | |
assert transform(b+1, a, b) == a | |
assert transform(b+2, a, b) == a+1 | |
print('All tests passed') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment