fork download
  1. def sort(arr)
  2. n = arr.length-1
  3. for i in 0..n-1
  4. min = arr[i]
  5. pos = i
  6. for j in i + 1..n
  7. if arr[j] < min
  8. min = arr[j]
  9. pos = j
  10. end
  11. end
  12. aux = arr[pos]
  13. arr[pos] = arr[i]
  14. arr[i] = aux
  15. end
  16. end
  17. def distinct(arr)
  18. x = [1,-2,-2,3,4,5,5,-2,1,10,20,30,10]
  19. y = []
  20. k = 0
  21. sort(x)
  22. k = 0
  23. y[k] = x[k]
  24. for i in 0..x.length-2
  25. if x[i] != x[i+1]
  26. k += 1
  27. y[k] = x[i+1]
  28. end
  29. end
  30. print y
  31. end
  32. def main
  33. arr = [1,-2,-2,3,4,5,5,-2,1,10,20,30,10]
  34. n = arr.length-1
  35. for i in 0..n-1
  36. if arr[i] != 0
  37. print arr[i], " "
  38. for j in i + 1..n
  39. if arr[i] == arr[j]
  40. arr[j] = 0
  41. end
  42. end
  43. end
  44. end
  45. end
  46. main
  47. distinct([])
  48.  
Success #stdin #stdout 0.01s 6340KB
stdin
Standard input is empty
stdout
1 -2 3 4 5 10 20 30 [-2, 1, 3, 4, 5, 10, 20, 30]