The Computer Language
24.11 Benchmarks Game

mandelbrot Matz's Ruby #8 program

source code

# The Computer Language Benchmarks Game
# https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
   
# line-by-line from Greg Buchholz's C program





def main(n)

    w, h, bit_num = 0, 0, 0, 0, 0
    byte_acc = 0
    i, iter = 0, 50
    x, y, limit = 2.0, 2.0, 2.0
    zr, zi, cr, ci, tr, ti = 0.0, 0.0, 0.0, 0.0, 0.0, 0.0

    h = ARGV[0].to_i; w = h

    puts "P4\n#{w} #{h}"

    h.times do |y|

        w.times do |x|

            zr, zi, tr, ti = 0.0, 0.0, 0.0, 0.0
            cr = 2.0*x/w - 1.5; ci = 2.0*y/h - 1.0

            iter.times do
                if tr+ti <= limit*limit            
                    zi = 2.0*zr*zi + ci;
                    zr = tr - ti + cr;
                    tr = zr * zr;
                    ti = zi * zi;
                end
            end            
            byte_acc = byte_acc << 1  
            if tr+ti <= limit*limit then byte_acc = byte_acc | 0x01 end            

            bit_num += 1        
                
            if bit_num == 8       
                print byte_acc.chr
                byte_acc = 0; 
                bit_num = 0     

                
            elsif x == w-1 
                        
                byte_acc = byte_acc << (8-w%8)         
                print byte_acc.chr
                byte_acc = 0; 
                bit_num = 0           
            end                          
       end
    end
end

n = (ARGV[0] || 200).to_i 
main n
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
ruby 1.8.7 
(2014-01-28
patchlevel 376)
[x86_64-linux]



 Thu, 07 Nov 2024 23:42:23 GMT

COMMAND LINE:
 /usr/share/rvm/rubies/ruby-1.8.7-head/bin/ruby  mandelbrot.mri-8.mri 16000

TIMED OUT after 3600s


(BINARY) PROGRAM OUTPUT NOT SHOWN