Skip to content

Instantly share code, notes, and snippets.

@ydawant
Created March 18, 2013 20:40
Show Gist options
  • Save ydawant/5190612 to your computer and use it in GitHub Desktop.
Save ydawant/5190612 to your computer and use it in GitHub Desktop.
Times Table
def times_table(rows)
array = Array.new(rows) { Array.new(rows) }
y=0
array.each do |x|
x.each do |i|
until y == rows
x[y] = 1
x[y] *= (y + 1)
y += 1
end
y=0
end
puts "#{x}\n"
end
end
@dontmitch
Copy link

What we worked on:

def times_table(rows)

  array = Array.new(rows) { Array.new(rows) }
  y=0
  array.each_with_index do |x, index|

    until y == rows
       x[y] = index+1
       x[y] *= (y + 1)
       y += 1
    end

    y=0
    puts "#{x}"

  end 
end

@dontmitch
Copy link

So, this isn't a solution but it should help you get to one. Instead of storing an entire row in "x" and then printing that at the end, you can "print" each value plus a space (which will keep everything on one line), and then after that row is complete you can print a new line (i.e. print "/n"). It would require a bit of reworking to get rid of x, but I think it will make things more simple.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment