This was the logic for inplace shuffle..
def inplace_shuffle(shuffle_me) shuffle_me.each.with_index do |val, index| random = rand(index..(shuffle_me.length-1)) shuffle_me[index], shuffle_me[random] = shuffle_me[random], shuffle_me[index] end end
Goes thru once so it has O[n] time and O[1] space.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This was the logic for inplace shuffle..
Goes thru once so it has O[n] time and O[1] space.