From: Robert Dober Date: 2007-03-12T05:18:24+09:00 Subject: Re: [QUIZ] SimFrost (#117) On 3/11/07, Christoffer Lern� wrote: > It's interesting that it looks like everyone populated their grid no Sir not me ;) but my code is longer and I wonder if it was worth it, now that I have looked at the outcomes of 55,60,65,70,75 and 80% vapor > using a randomizer for each position in the grid. > > This is is obviously fast, but for small grids (and low percentages), > the percentage of actual generated vapour particles may be off by > quite a bit. > > For a 10x10 grid and 10% vapour, the amount of particles typically > range between 5 and 15, which in turn makes the finished frost look > very different from run to run. > > I was thinking of ways to solve this. Obviously trying to randomly > put vapour particles into an array - and retry if it already > cointains vapur - is not ideal... Almost interminable, I was using it too, look at Torus_#set_vapors in my solution > > My best trick is this one: > > require 'enumerator' > percentage = 30 > width = 30 > height = 20 > vapour = width * height * percentage / 100 > vacuum = width * height - vapour > grid = [] > (Array.new(vacuum, ' ') + Array.new(vapour, '.')).sort_by > { rand }.each_slice(width) { |s| grid << s } > > This gives us a grid that is guaranteed to have the correct initial > proportion of vapour. > > Anyone else with a more elegant solution to the problem? > > > Christoffer > > > Robert -- We have not succeeded in answering all of our questions. In fact, in some ways, we are more confused than ever. But we feel we are confused on a higher level and about more important things. -Anonymous