Skip to content

Instantly share code, notes, and snippets.

@ErikRamses
Created July 1, 2013 07:01
Show Gist options
  • Save ErikRamses/5898869 to your computer and use it in GitHub Desktop.
Save ErikRamses/5898869 to your computer and use it in GitHub Desktop.
Generador
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
@stibiumz
Copy link

Gracias, échale un vistazo a generador.co

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