Skip to content

Instantly share code, notes, and snippets.

@steshaw
Created July 12, 2023 04:24
Show Gist options
  • Save steshaw/92fc9b06399048b8ad61a96c4b13dc6d to your computer and use it in GitHub Desktop.
Save steshaw/92fc9b06399048b8ad61a96c4b13dc6d to your computer and use it in GitHub Desktop.
def parity(p):
return sum(
1
for (x, px) in enumerate(p)
for (y, py) in enumerate(p)
if x < y and px > py
) % 2 == 0
print(parity([1,2,3]))
print(parity([1,2,3,4]))
print(parity([3,1,2,4]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment