From: Bil Kleb Date: 2007-11-12T10:40:00+09:00 Subject: Re: comp.lang.fortran challenge Bil Kleb wrote: > Having Ruby fun with the comp.lang.fortran folks: > > http://tinyurl.com/38o8ex > http://tinyurl.com/2pw22q > > Please riff a better Ruby answer... My current answer to the challenge... require 'scanf' require 'open-uri' def write_uvs(u,v) u = u[0...v.size] # limit U's size to V's puts u, v # write Us & Vs u.zip(v).each do |u_line,v_line| # zip Us & Vs together u_value, v_value = u_line.scanf("%14c %f").last, v_line.scanf("%14c %f").last printf "#{u_line[/.*=/].sub(/U/,'UV')} %7.3f\n", u_value*v_value # write UV end end u, v = [], [] # initialize U & V arrays open 'http://home.earthlink.net/~dave_gemini/demo.in' do |iostream| iostream.each_line do |line| case line when /^time/ then # found time delimiter write_uvs(u,v) and u.clear and v.clear puts "\n" + line.sub( /time\s*:/, 'for time' ) + "\n" # write time when /^U/ then # add to U array u << line when /^V/ then # add to V array v << line unless v.size == u.size # limit V's size to U's end end end write_uvs(u,v) Later, -- Bil Kleb http://tufte-latex.googlecode.com