30
loading...
This website collects cookies to deliver better user experience
$N
.1
if it is otherwise 0
.sprintf '%b'
, and then compare this string to the reversed string.$ ./ch-1.pl 5
1
$ ./ch-1.pl 4
*
and x
, I specify the treasure spots in chess notation (a1 = bottom left, f8 = top right). While the task specifies six pieces of treasure, you can specify as many or as few as required._input_to_targets
subroutine converts the chess notation into cell positions (a1 = 0,0, a8 = 0,7). It also adds a8 as the starting position, and checks that there are no duplicates._get_intermediate_moves
subroutine._get_permutation
function that was copied from the second task of week 109. For six pieces of treasure, there are 720 (6!) possible permutations, since we must always start at the top left position.@least_moves
array._cn
function. If the cell has a piece of treasure, then I put asterisks around the cell.$ ./ch-2.pl e6 d4 c3 a2 b2 b1
The shortest path is 12 steps
*a8* » c7 » *e6* » *d4* » b5 » *c3* » *a2* » c3 » *b1* » c3 » d1 » *b2*
30