Skip to content

Instantly share code, notes, and snippets.

@shtakai
Created May 6, 2016 02:09
Show Gist options
  • Save shtakai/58183b6a0764b44001b22e47af0dfb4e to your computer and use it in GitHub Desktop.
Save shtakai/58183b6a0764b44001b22e47af0dfb4e to your computer and use it in GitHub Desktop.
def shuffle(l)
return l[0] if l.size == 1
i = l.index(l.sample)
h = l[i]
l.delete_at(i)
return [h, shuffle(l)].flatten
end
array = [1,2,3,4,5,6]
p shuffle(array)
@shtakai
Copy link
Author

shtakai commented May 6, 2016

TODO:

  • line5: use l[(0...i)] + l[i...l.size-1]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment