find the slope between two points in ruby

To find the slope between two points in Ruby, you can use the formula:

main.rb
slope = (y2 - y1) / (x2 - x1)
30 chars
2 lines

where (x1, y1) and (x2, y2) are the coordinates of the two points.

Here's an example code block that calculates the slope between two points:

main.rb
x1 = 2
y1 = 5
x2 = 5
y2 = 10

slope = (y2 - y1) / (x2 - x1)

puts "The slope between (#{x1}, #{y1}) and (#{x2}, #{y2}) is #{slope}."
133 chars
9 lines

This should output:

main.rb
The slope between (2, 5) and (5, 10) is 1.6666666666666667.
60 chars
2 lines

gistlibby LogSnag