Ruby Interview Questions

1: Write a program to print out a multiplication table, from 1×1 to 12×12.
========================
x = (1..12)
y = (1..12)

print ‘ ‘
x.each {|i| print “%-3d ” % i}
print “\n ”
x.each {|i| print ‘—- ‘}
print “\n”

y.each do |j|
print “%-3d| ” % j
x.each {|i| print “%-3d ” % (i*j)}
print “\n”
end
==================

2: Reversing a linked list in Ruby

http://commandercoriander.net/blog/2012/12/23/reversing-a-linked-list-in-ruby/
=================================================================
3: ruby put variable in range

a = [1,2,3,5,7]
arrayl=a.length+1
b = (1..arrayl).to_a
p b-a #=> [4, 6]

==============================================

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: