On Fri, Dec 7, 2012 at 4:24 AM, 7stud -- <[email protected]> wrote:
> Joao Silva wrote in post #1088123:

> results = []
> rows = 9
> columns = 8

Hey, that's cheating. :-) The algorithm must determine these from the input.

Two more solutions

puts "-- 1 --"

lines = []
max = 0

File.foreach "t" do |line|
  line.chomp!
  lines << line
  max = [max, line.length].max
end

max.times do |i|
  puts lines.map {|l| l[i] || ' '}.join
end

puts "-- 2 --"

lines = []

File.foreach "t" do |line|
  line.chomp!
  line.each_char.each_with_index do |c, i|
    (lines[i] ||= '') << c
  end
end

puts lines


Kind regards

robert



--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

-- You received this message because you are subscribed to the Google Groups 
ruby-talk-google group. To post to this group, send email to 
[email protected]. To unsubscribe from this group, send email 
to [email protected]. For more options, visit this 
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en

Reply via email to