Skip to content

Instantly share code, notes, and snippets.

@aaronbond
Created July 16, 2019 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronbond/eedf6c44401f68664340ff03d8bcac80 to your computer and use it in GitHub Desktop.
Save aaronbond/eedf6c44401f68664340ff03d8bcac80 to your computer and use it in GitHub Desktop.
if we go right to left i think we can get the best solution so we start with this
2 3 4 5 6 7 8 9 1
check the position of the end against its value, doesn't work so we check pos -1 and pos -2 and if we find we do a swap
and increment count if not we say too chaotic
2 3 4 5 6 7 8 1 9 > count = 1
2 3 4 5 6 7 1 8 9 > count = 2
2 3 4 5 6 1 7 8 9 > count = 3
etc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment