------art_17925_9518028.1173619425212
Content-Type: multipart/alternative; 
	boundary---art_17926_15519589.1173619425212"

------art_17926_15519589.1173619425212
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

right, code got mangled, here's the file

On 3/11/07, Christoffer Lern<lerno / dragonascendant.com> wrote:
>
> Fun Quiz!
>
> Here's my solution (ASCII only I'm afraid). I use a wrapper object to
> handle a neighbourhood. Since I only allow access one at a time, I
> simply recycled a single object. This is unsafe in the general case,
> but works nicely here I think.
>
> My code for rotations are explicit than calculated, but I find it
> easier to read and understand what is going on.
>
>
> #!/usr/bin/env ruby -w
>
> module SimFrost
>
>    class FrostGrid
>
>      attr_reader :data
>
>      def initialize(width, height, percent)
>        @width, @height = width, height
>        @data = Array.new(height) { Array.new(width) { rand * 100 <
> percent ? '.' : ' ' }.join }
>        self[width / 2, height / 2] = ?*
>        @neighbourhood = Neighbourhood.new(self)
>        @tick = 0
>      end
>
>      def [](x, y)
>        @data[y % @height][x % @width]
>      end
>
>      def []=(x, y, value)
>        @data[y % @height][x % @width] = value
>      end
>
>      def tick
>        @tick += 1
>        vapour = 0
>        each_neighbourhood do |neighbourhood|
>          neighbourhood.mutate
>          vapour += 1 if neighbourhood.contains_vapour?
>        end
>        vapour
>      end
>
>      def draw_freeze
>        draw # Before we start freezing
>        draw while tick > 0
>        draw # After everything is frozen
>      end
>
>      def draw
>        puts "Tick: #{@tick}"
>        puts "+" + "-" * @width + "+"
>        @data.each { |row| puts "|#{row}|" }
>        puts "+" + "-" * @width + "+"
>      end
>
>      def each_neighbourhood
>        @tick.step(@tick + @height, 2) do |y|
>          @tick.step(@tick + @width, 2) do |x|
>            yield @neighbourhood[x, y]
>          end
>        end
>      end
>
>    end
>
>    class Neighbourhood
>
>      2.times do |y|
>        2.times do |x|
>          class_eval "def xy#{x}#{y}; @grid[@x + #{x}, @y + #{y}]; end"
>          class_eval "def xy#{x}#{y}=(v); @grid[@x + #{x}, @y + #{y}]
> = v; end"
>        end
>      end
>
>      def initialize(grid)
>        @grid = grid
>      end
>
>      def [](x, y)
>        @x, @y = x, y
>        self
>      end
>
>      def ccw90
>        self.xy00, self.xy10, self.xy01, self.xy11 = xy10, xy11, xy00,
> xy01
>      end
>
>      def cw90
>        self.xy00, self.xy10, self.xy01, self.xy11 = xy01, xy00, xy11,
> xy10
>      end
>
>      def each_cell
>        @y.upto(@y + 1) { |y| @x.upto(@x + 1) { |x| yield x, y } }
>      end
>
>      def contains?(c)
>        each_cell { |x, y| return true if @grid[x, y] == c }
>        false
>      end
>
>      def contains_ice?
>        contains? ?*
>      end
>
>      def contains_vapour?
>        contains? ?.
>      end
>
>      def freeze
>        each_cell { |x, y| @grid[x, y] = ?* if @grid[x, y] == ?. }
>      end
>
>      def rotate_random
>        rand < 0.5 ? ccw90 : cw90
>      end
>
>      def mutate
>        contains_ice? ? freeze : rotate_random
>      end
>
>      def to_s
>        "+--+\n+" << xy00 << xy10 << "+\n+" << xy01 << xy11 << "+\n+--+"
>      end
>    end
>
>
>    def SimFrost.simfrost(width, height, percent = 50)
>      FrostGrid.new(width, height, percent).draw_freeze
>    end
>
> end
>
> if __FILE__ == $PROGRAM_NAME
>    SimFrost::simfrost(40, 20, 35)
> end
>
>
>
>

------art_17926_15519589.1173619425212
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

right, code got mangled, here&#39;s the file<br><br><div><span class="gmail_quote">On 3/11/07, <b class="gmail_sendername">Christoffer Lern/b>lt;lerno / dragonascendant.com&gt; wrote:
</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Fun Quiz!<br><br>Here&#39;s my solution (ASCII only I&#39;m afraid). I use a wrapper object to
<br>handle a neighbourhood. Since I only allow access one at a time, I<br>simply recycled a single object. This is unsafe in the general case,<br>but works nicely here I think.<br><br>My code for rotations are explicit than calculated, but I find it
<br>easier to read and understand what is going on.<br><br><br>#!/usr/bin/env ruby -w<br><br>module SimFrost<br><br>&nbsp;&nbsp; class FrostGrid<br><br>&nbsp;&nbsp;&nbsp;&nbsp; attr_reader :data<br><br>&nbsp;&nbsp;&nbsp;&nbsp; def initialize(width, height, percent)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @width, @height = width, height
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @data = Array.new(height) { Array.new(width) { rand * 100 &lt;<br>percent ? &#39;.&#39; : &#39; &#39; }.join }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self[width / 2, height / 2] =*<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @neighbourhood = Neighbourhood.new(self)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @tick = 0
<br>&nbsp;&nbsp;&nbsp;&nbsp; end<br><br>&nbsp;&nbsp;&nbsp;&nbsp; def [](x, y)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @data[y % @height][x % @width]<br>&nbsp;&nbsp;&nbsp;&nbsp; end<br><br>&nbsp;&nbsp;&nbsp;&nbsp; def []=(x,, value)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @data[y % @height][x % @width] = value<br>&nbsp;&nbsp;&nbsp;&nbsp; end<br><br>&nbsp;&nbsp;&nbsp;&nbsp; def tick<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @tick += 1
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vapour = 0<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; each_neighbourhood do |neighbourhood|<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; neighbourhood.mutate<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vapour += 1 if neighbourhood.contains_vapour?<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vapour<br>&nbsp;&nbsp;&nbsp;&nbsp; end<br><br>&nbsp;&nbsp;&nbsp;&nbsp; def draw_freeze
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; draw # Before we start freezing<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; draw while tick &gt; 0<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; draw # After everything is frozen<br>&nbsp;&nbsp;&nbsp;&nbsp; end<br><br>&nbsp;&nbsp;&nbsp;&nbsp; def draw<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; puts &quot;Tick: #{@tick}&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; puts &quot;+&quot; + &quot;-&quot; * @width + &quot;+&quot;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @data.each { |row| puts &quot;|#{row}|&quot; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; puts &quot;+&quot; + &quot;-&quot; * @width + &quot;+&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp; end<br><br>&nbsp;&nbsp;&nbsp;&nbsp; def each_neighbourhood<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @tick.step(@tick + @height, 2) do |y|
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @tick.step(@tick + @width, 2) do |x|<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; yield @neighbourhood[x, y]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end<br>&nbsp;&nbsp;&nbsp;&nbsp; end<br><br>&nbsp;&nbsp; end<br><br>&nbsp;&nbsp; class Neighbourhood<br><br>&nbsp;&nbsp;&nbsp;&nbsp; 2.times do |y|<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2.times
 do |x|<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; class_eval &quot;def xy#{x}#{y}; @grid[@x + #{x}, @y + #{y}]; end&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; class_eval &quot;def xy#{x}#{y}=(v); @grid[@x + #{x}, @y + #{y}]<br>= v; end&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end<br>&nbsp;&nbsp;&nbsp;&nbsp; end<br><br>&nbsp;&nbsp;&nbsp;&nbsp; def initialize(grid)
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @grid = grid<br>&nbsp;&nbsp;&nbsp;&nbsp; end<br><br>&nbsp;&nbsp;&nbsp;&nbsp; def [](x, y)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @x, @y = x, y<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self<br>&nbsp;&nbsp;&nbsp;&nbsp; end<br><br>&nbsp;&nbsp;&nbsp;&nbsp; def ccw90<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.xy00, self.xy10, self.xy01, self.xy11 = xy10, xy11, xy00,<br>xy01<br>&nbsp;&nbsp;&nbsp;&nbsp; end
<br><br>&nbsp;&nbsp;&nbsp;&nbsp; def cw90<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.xy00, self.xy10, self.xy01, self.xy11 = xy01, xy00, xy11,<br>xy10<br>&nbsp;&nbsp;&nbsp;&nbsp; end<br><br>&nbsp;&nbsp;&nbsp;&nbsp; def each_cell<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @y.upto(@y + 1) { |y| @x.upto(@x + 1) { |x| yield x, y } }<br>&nbsp;&nbsp;&nbsp;&nbsp; end
<br><br>&nbsp;&nbsp;&nbsp;&nbsp; def contains?(c)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; each_cell { |x, y| return true if @grid[x, y] == c }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; false<br>&nbsp;&nbsp;&nbsp;&nbsp; end<br><br>&nbsp;&nbsp;&nbsp;&nbsp; def contains_ice?<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; contains? ?*<br>&nbsp;&nbsp;&nbsp;&nbsp; end<br><br>&nbsp;&nbsp;&nbsp;&nbsp; def contains_vapour?<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; contains? ?.<br>&nbsp;&nbsp;&nbsp;&nbsp; end<br><br>&nbsp;&nbsp;&nbsp;&nbsp; def freeze<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; each_cell { |x, y| @grid[x, y] = ?* if @grid[x, y] == ?. }<br>&nbsp;&nbsp;&nbsp;&nbsp; end<br><br>&nbsp;&nbsp;&nbsp;&nbsp; def rotate_random<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rand &lt; 0.5 ? ccw90 :w90<br>&nbsp;&nbsp;&nbsp;&nbsp; end<br><br>
&nbsp;&nbsp;&nbsp;&nbsp; def mutate<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ontains_ice? ? freeze : rotate_random<br>&nbsp;&nbsp;&nbsp;&nbsp; end<br><br>&nbsp;&nbsp;&nbsp;&nbsp; def to_s<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;+--+\n+&quot; &lt;&lt; xy00 &lt;&lt; xy10 &lt;&lt; &quot;+\n+&quot; &lt;&lt; xy01 &lt;&lt; xy11 &lt;&lt; &quot;+\n+--+&quot;
<br>&nbsp;&nbsp;&nbsp;&nbsp; end<br>&nbsp;&nbsp; end<br><br><br>&nbsp;&nbsp; def SimFrost.simfrost(width, height, percent = 50)<br>&nbsp;&nbsp;&nbsp;&nbsp; FrostGrid.new(width, height, percent).draw_freeze<br>&nbsp;&nbsp; end<br><br>end<br><br>if __FILE__ == $PROGRAM_NAME<br>&nbsp;&nbsp; SimFrost::simfrost(40, 20, 35)
<br>end<br><br><br><br></blockquote></div><br>

------art_17926_15519589.1173619425212--

------art_17925_9518028.1173619425212
Content-Type: application/octet-stream; name=snowflake.rb
Content-Transfer-Encoding: base64
X-Attachment-Id: f_ez5j2szu
Content-Disposition: attachment; filename="snowflake.rb"

Y2xhc3MgU25vd2ZsYWtlDQogIGF0dHJfcmVhZGVyIDpncmlkLCA6dmFwb3INCiAgZGVmIGluaXRp
YWxpemUgKHlfc2l6ZT0yNCwgeF9zaXplPTMwLCB2YXBvcl9wZXJjZW50PTMwKQ0KICAgIEB5X3Np
emU9eV9zaXplLzIqMiAgICAjdGhpcyBzaG91bGQgdGFrZSBjYXJlIG9mIHRob3NlIG9kZCBudW1i
ZXJzDQogICAgQHhfc2l6ZT14X3NpemUvMioyDQogICAgQHZhcG9yX3BlcmNlbnQ9dmFwb3JfcGVy
Y2VudA0KICAgIEB2YWN1dW09IiAiDQogICAgQHZhcG9yPSIrIg0KICAgIEBpY2U9IioiDQogICAg
QG9mZnNldD0xDQogICAgY3JlYXRlX2dyaWQNCiAgZW5kDQogIA0KICBkZWYgY3JlYXRlX2dyaWQN
CiAgICBAZ3JpZD1BcnJheS5uZXcoQHlfc2l6ZSl7QXJyYXkubmV3KEB4X3NpemUpfQ0KICAgIEBn
cmlkLmNvbGxlY3QhIGRvIHxyb3d8DQogICAgICByb3cuY29sbGVjdCEgZG8gfHNxdWFyZXwNCiAg
ICAgICAgcmFuZCgxMDApIDwgQHZhcG9yX3BlcmNlbnQgPyBAdmFwb3IgOiBAdmFjdXVtDQogICAg
ICBlbmQNCiAgICBlbmQNCiAgICBAZ3JpZFtAeV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cu
aW5jbHVkZT8ocy52YXBvcil9LmluY2x1ZGU/KHRydWUpDQogIHB1dHMgcw0KICA1LnRpbWVzIGRv
IHB1dHMgZW5kDQogIHNsZWVwKDAuMSkNCiAgcy5jaGVja19uZWlnaGJvcmhvb2RzDQplbmQNCiAg
cHV0cyBzDQoNCj1iZWdpbiBSdW5uaW5nIHRocnUgdGhlIGZpbmlzaCBsaW5lDQoNCiAgICAgICAg
ICAgICAgICoqDQogICAgICAgKiAgICAgICAqDQogICAgICAgKiAgICogICoNCiAgICAgICAgKiAg
ICoqDQogICAgICAgICAqKiAqKg0KICAgICAgICAgICoqDQogICAgICAgICoqKiAqDQogICAgICAg
ICAgKioqDQogICAgICAgICAgICogKg0KICAgICAgICAgICAgKiAqDQogICAgICAgICAgICAgKg0K
ICAgICAgICAgICAgICoNCj1lbmQ------art_17925_9518028.1173619425212--