#!/bin/ruby def print_shortest_path(n, i_start, j_start, i_end, j_end) #never got to the if i_start.odd? && i_end.even? || i_start.even? && i_end.odd? return puts "Impossible" end if ((i_start % 4) == (i_end % 4)) && ( j_start.odd? != j_end.odd? ) return puts "Impossible" end if ((i_start % 4) != (i_end % 4)) && ( j_start.odd? == j_end.odd? ) return puts "Impossible" end current_row = i_start current_col = j_start count = 0 path = [] #priority UL, UR, R, LR, LL, L until current_row == i_end && current_col == j_end if current_row < i_end if current_col < j_end || current_col == j_end #LR current_row += 2 current_col += 1 count +=1 path << :LR elsif current_col > j_end #LL current_row += 2 current_col -= 1 count +=1 path << :LL end elsif current_row > i_end if current_col < j_end #UR current_row -= 2 current_col += 1 count +=1 path << :UR elsif current_col > j_end || current_col == j_end #UL current_row -= 2 current_col -= 1 count +=1 path << :UL end elsif current_row == i_end if current_col < j_end #R current_col += 2 count +=1 path << :R elsif current_col > j_end #L current_col -= 2 count +=1 path << :L end end end puts count path.each { |path| print "#{path} " } end n = gets.strip.to_i i_start, j_start, i_end, j_end = gets.strip.split(' ') i_start = i_start.to_i j_start = j_start.to_i i_end = i_end.to_i j_end = j_end.to_i print_shortest_path(n, i_start, j_start, i_end, j_end)