Auto-alignment problem

This night I meet a problem with the auto-alignment function, I post the code under here, the issue may be with “while”, that is not well gestited.

now = Time.now.to_i
use_random_seed now
volte = 16
a = []
n = 0

volte.times do
  x = rand_i(51)
  a[n] = x
  n = n + 1
end
puts a


print "Inizio verifica numeri uguali"
i = 0
xi = 1
while((volte-1)!=i) do
  j = 1
  if (xi == 0)
    i = 0
    xi = 1
  end
  print "Eseguo ciclo per i = ",i
  while(volte!=j) do
    if(i!=j)
      if(a[i]==a[j])
        puts a
        print "Posizione",i,"uguale a",j
        print "Numero uguale",a[i]
        a[i] = rand_i(51)
        print "Sostituito con",a[i]
        puts a
        j = 0
        xi = 0
      end
    end
    j = j + 1
  end
  i = i + 1
  print "*********************************"
end

print "Nuovo array senza ripetizioni"
puts a

Yes I’ve noticed this before. The code will still work just doesn’t look so nice. To be fair the code goes outside the strict supported Sonic Pi code in that while (and similar eg until) is not part of the defined sp language. It could perhaps be fixed but is unlikely at present given the support that Sam can afford to give.

1 Like

Thank you for the explanation @robin.newman .