On Wed, 12 Oct 2005 14:07:08 +0200, daz <dooby / d10.karoo.co.uk> wrote:

>
> Harold Hausman wrote:
>> Hi,
>>
>> [...] the first code I've shared with you guys:
>
> Hi Harold - and thanks for doing that.

Yes, a really nice solution.

> ...

> Maybe we'll see a smaller fowl soon :-)

I am not sure if you meant golfing by "a smaller fowl", but anyway here  
are my attempts:

The first version version is just a refactoring like yours:

GRADIENT = %w|D Y 8 S 6 5 J j t c + i ! ; : .|
file = File.new(ARGV.shift || "ducky.bmp", "rb")
file.read(2+4+4+4+4) # headers
image_x, image_y = file.read(8).unpack("VV") # width / height
file.read(2+2+24) # headers

puts((0...image_y).collect do |row|
   (0...image_x).collect do |col|
     GRADIENT[(file.read(3).unpack("CCC").inject { |a,b| a+b } / 3) >> 4]
   end.join
end.reverse)

It writes to stdout and optionally uses ARGV.shift as input.

And here are two different short version, they need ARGV[0] and also write  
to stdout:

f=open$*[0],"rb";w,h=f.read(54)[18,8].unpack"VV"
puts((1..h).collect{(1..w).collect{"DY8S65Jjtc+i!;:."[f.read(3).unpack(
"CCC").inject{|a,b|a+b}/48,1]}.join}.reverse)


d=IO.read$*[0];puts  
d[54..-1].scan(/.../m).map{|s|"DY8S65Jjtc+i!;:."[s.unpack(
"CCC").inject{|a,b|a+b}/48,1]}.join.scan(/.{#{d[18,4].unpack"V"}}/).reverse


The second one might be problematic on Windows (I am not sure if IO.read  
reads binary or not).

Dominik