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 Answer

edited body
Source Link
mazzy
  • 7.2k
  • 2
  • 13
  • 23

PowerShell, 43 bytes (Iterative method)

param($n)for(;!((do{$x+=1..$n|random)%$n)){}until($x%$n)$x

Try it online! Try it online!


PowerShell, 48 bytes (recursive method)

filter f{if($_-eq($x=1..$_|random)){$x+=$_|f}$x}

Try it online!

PowerShell, 43 bytes (Iterative method)

param($n)for(;!(($x+=1..$n|random)%$n)){}$x

Try it online!


PowerShell, 48 bytes (recursive method)

filter f{if($_-eq($x=1..$_|random)){$x+=$_|f}$x}

Try it online!

PowerShell, 43 bytes (Iterative method)

param($n)do{$x+=1..$n|random}until($x%$n)$x

Try it online!


PowerShell, 48 bytes (recursive method)

filter f{if($_-eq($x=1..$_|random)){$x+=$_|f}$x}

Try it online!

Source Link
mazzy
  • 7.2k
  • 2
  • 13
  • 23

PowerShell, 43 bytes (Iterative method)

param($n)for(;!(($x+=1..$n|random)%$n)){}$x

Try it online!


PowerShell, 48 bytes (recursive method)

filter f{if($_-eq($x=1..$_|random)){$x+=$_|f}$x}

Try it online!

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