fork download
  1. nums = []
  2.  
  3. 5.times do |i|
  4. nums[i] = 20+Random.rand(11)
  5. end
  6.  
  7. sorted = false
  8. while sorted == false
  9.  
  10. sorted = true
  11. nums[1..-1].each do |i|
  12. if nums[i] > nums[i-1]
  13. sorted = false
  14. break
  15. end
  16. end
  17.  
  18. if sorted == false
  19. first_i = Random.rand(nums.length)
  20. second_i = first_i
  21.  
  22. while first_i == second_i
  23. second_i = Random.rand(nums.length)
  24. end
  25.  
  26. tmp = num[first_i]
  27. num[first_i] = num[second_i]
  28. num[second_i] = tmp
  29. end
  30.  
  31. end
Runtime error #stdin #stdout 0s 4760KB
stdin
Standard input is empty
stdout
Standard output is empty