Skip to content

Instantly share code, notes, and snippets.

@pshushereba
Created March 30, 2016 21:54
Show Gist options
  • Select an option

  • Save pshushereba/3aa5abf89fc112138a3709ba3865a706 to your computer and use it in GitHub Desktop.

Select an option

Save pshushereba/3aa5abf89fc112138a3709ba3865a706 to your computer and use it in GitHub Desktop.

Revisions

  1. pshushereba revised this gist Mar 30, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion distance.rb
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,6 @@ def distance(destination_row, destination_col)
    return (destination_col - current_column_index).abs
    # destination_col - current_row_index
    else
    puts "Invalid Inputs"
    puts "Invalid Input"
    end
    end
  2. pshushereba created this gist Mar 30, 2016.
    12 changes: 12 additions & 0 deletions distance.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    def distance(destination_row, destination_col)
    if self.vertical?(destination_row, destination_col)
    return (destination_row - current_row_index).abs
    elsif self.horizontal?(destination_row, destination_col)
    return (destination_col - current_column_index).abs
    elsif self.diagonal?(destination_row, destination_col)
    return (destination_col - current_column_index).abs
    # destination_col - current_row_index
    else
    puts "Invalid Inputs"
    end
    end