------art_184499_8098599.1180294077921
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

I've gone for short but un-ruby-esque solution. Outputs an image in .pbm
format to stdout.

Regards,
Raf


$ cat rq125_fractals_rafc.rb
#!/usr/bin/ruby -w

# 0: North
# 1: East
# 2: South
# 3: West

#Transformation: the sequence of segments that a
#segment going North is transformed into:
t   0, 3, 0, 1, 0]

#Starting situation: one segment going East:
f   1]

#Build the fractal:
ARGV[0].to_i.times{ f  .map{ |g| t.map{ |u| ( g + u) % 4}}.flatten}


#Draw the result:

dx   0, 1, 0, -1]
dy   1, 0, -1, 0]

#Determine dimension of drawing:
x  
y  
minx  
miny  
maxx  
maxy  
f.each do |g|
  x + x[g]
  y + y[g]
  minx  x, minx].min
  miny  y, miny].min
  maxx  x, maxx].max
  maxy  y, maxy].max
end

dimx  maxx - minx) * 2 + 3
dimy  maxy - miny) * 2 + 3

drawing  rray.new( dimy) { Array.new( dimx, 0)}

#Draw:
x  minx * 2 + 1
y  miny * 2 + 1

drawing[y][x]  

f.each{ |g|
  2.times {
    x + x[g]
    y + y[g]
    drawing[y][x]  
  }
}

#Output PBM:
puts 'P1'
puts "#{dimx} #{dimy}"
drawing.reverse_each { |row| puts row.join( ' ')}
__END__

$ #Usage:
$ ./rq125_fractals_rafc.rb 5 > f5.pbm

------art_184499_8098599.1180294077921--