On Sep 6, 2007, at 4:47 PM, Morton Goldberg wrote:

> <code>
> zero_cells = grid.select { |cell| cell.cell_type == 0 }
> n = (0.6 * zero_cells.size).round
> zero_cells[0..n-1].each { |cell| cell.cell_type = 2 }
> zero_cells[n..-1].each { |cell| cell.cell_type = 3 }
> grid.print_field_values
> </code>

I've thought of a more efficient way.

<code>
zero_cells = grid.select { |cell| cell.cell_type == 0 }
n = zero_cells.size
k = (0.6 * n).round
(0...k).each { |i| zero_cells[i].cell_type = 2 }
(k...n).each { |i| zero_cells[i].cell_type = 3 }
</code>

Regards, Morton