#!/usr/bin/perl # http://perlmonks.org/?node_id=1211497 use strict; use warnings; sub up { my ($row, $col) = split /-/, $_[0]; my ($startrow, $startcol) = split /-/, $_[-1]; return $_[0] eq $_[-1] ? "@_[0..@_-2]\n" : ($row - $startrow > 0 && $col - $startcol > 0 && up( ~-$row . '-' . ~-$col, @_ ) ) . ($row - $startrow > $col - $startcol && up( ~-$row . '-' . $col, @_ ) ); } print up( '3-1', '1-0' ); # bottom, top