Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Revisions

5 of 5
added 9 characters in body
digEmAll
  • 5.1k
  • 15
  • 22

R, 27 bytes

any(rank(x<-scan(),,'f')-x)

Try it online!

Returns FALSE for Truthy, TRUE for FALSY (just to shave one byte)

Explanation:

If the array containing the rank of each value is equal to the input array, then it's a permutation of 1..n

Note:
5 bytes are wasted because in rank function the default handling strategy in case of ties is "average their ranks" instead of any of the other possibilities... argh!

digEmAll
  • 5.1k
  • 15
  • 22

AltStyle によって変換されたページ (->オリジナル) /