Created
July 1, 2013 07:01
-
-
Save ErikRamses/5898869 to your computer and use it in GitHub Desktop.
Generador
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Generacion | |
attr_accessor :arreglo, :aunico, :arepeticion, :numero, :repeticiones #funcion utilizada para el acceso a objetos | |
arreglo=[] | |
arepeticion=[] | |
repeticiones = 0 | |
aunic=[] #se declaran arreglos y variables a utilizar | |
puts "Ingrese la cantidad de numeros a generar: " #pide el numero de elementos | |
numero = gets | |
numero.to_i.times.map do |num| #Generacion de numeros aleatorios | |
arreglo << 10000 + Random.rand(99999) | |
end | |
arreglo.each do |elemento| #Entontrar repeticiones | |
if arreglo.count(elemento) > 1 | |
arepeticion << elemento.to_i | |
end | |
end | |
arepeticion.each do |indice| #Eliminar repetidos | |
arreglo.delete_if do |elemento| | |
elemento == indice | |
end | |
end | |
puts "Numeros repetidos por lo menos una vez: #{arepeticion.uniq}" | |
puts "Repeticiones totales #{arepeticion.count}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gracias, échale un vistazo a generador.co