Skip to content

Instantly share code, notes, and snippets.

@benj2240
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save benj2240/f679ec976d13bdefaba6 to your computer and use it in GitHub Desktop.

Select an option

Save benj2240/f679ec976d13bdefaba6 to your computer and use it in GitHub Desktop.
File.open(ARGV[0]).each_line do |line|
# expression to pull positive or negative ints out of the input line
# expects "(x, y) (a, b)"
regex = /\((?<x>\-?\d+), (?<y>\-?\d+)\) \((?<a>\-?\d+), (?<b>\-?\d+)\)/
input = regex.match(line.strip)
# pull variables out of match data; cast them from string to int
x,y,a,b = ["x","y","a","b"].map{|var| input[var].to_i}
# print integer distance
puts (((x-a)**2+(y-b)**2)**0.5).to_i
end
File.open(ARGV[0]).each_line do |line|
line.
scan(/-?\d+/).
map{|n| n.to_i}.
each_cons(4){|x,y,a,b|
puts (((x-a)**2+(y-b)**2)**0.5).to_i
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment