Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

11
  • 8
    \$\begingroup\$ I am disappointed that we are not allowed to be "clever" and use library functions other than "get a random number". Do we want to look at yet another 69 implementations of Fisher-Yates shuffling? Please consider removing this rule in future tasks. Also, why a limit on time complexity? Please consider relaxing it to at least O(n^2); I also think someone might find an especially golfed implementation if you allow O(n!). \$\endgroup\$ Commented Feb 3, 2015 at 20:58
  • 7
    \$\begingroup\$ @anatolyg Removing the restrictions amounts to every answer being either sortby(random) (the reason for the time restriction) or simply .shuffle() (the reason for the built-ins restriction), which I think is a lot less clever than having to implement Fisher-Yates or some other approach. \$\endgroup\$ Commented Feb 3, 2015 at 21:03
  • 1
    \$\begingroup\$ If shuffling in place, does a function have to return the array, or is it enough that it is modified? Can I write a function for shuffle(array) instead of newArray=shuffle(array)? \$\endgroup\$ Commented Feb 4, 2015 at 2:30
  • 1
    \$\begingroup\$ @Bakuriu Claiming that you can sort in linear time if the numbers are fixed is a bit like claiming you can do anything in O(1) if the input sizes are fixed. Also the relevant restriction is fixed-size arrays, not fixed-size integers - because the array size determines how large you need your random numbers to be. Anyway, the limitation on time complexity are of course for the general algorithm you implement, whereas the limits on input sizes are in place so you don't have to use arbitrary-precision integers if your language doesn't use them out of the box. \$\endgroup\$ Commented Feb 4, 2015 at 9:48
  • 2
    \$\begingroup\$ Why is Adám's solution coming up as 43319 bytes when it's actually 14? \$\endgroup\$ Commented May 14, 2017 at 0:10