Created
November 15, 2025 16:25
-
-
Save SqrtRyan/a6a7f0e821cc1aaa1af6d47ed2cbe662 to your computer and use it in GitHub Desktop.
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
| #CYCLESORT!!! | |
| def swap(a,i,j): | |
| a[i],a[j]=a[j],a[i] | |
| class Counted: | |
| def __repr__(self): | |
| return 'X' | |
| X=Counted() | |
| a=shuffled([3,1,7,8,8,3,3,3,2,4,5,5,0]) | |
| n=len(a) | |
| assert max(a)<n | |
| z=[] | |
| for i in range(n): | |
| while i!=a[i] and a[i]!=X: | |
| j=a[i] | |
| k=a[j] | |
| if j==k: | |
| #Swap would make no difference | |
| z+=[j] | |
| a[i]=X | |
| else: | |
| swap(a,i,j) | |
| print(a) | |
| #CYCLESORT!!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment