Вот один из способов сделать это. Написание более обобщенного алгоритма решения лабиринта с использованием логики шага данных SAS остается как упражнение для читателя, но это должно работать для лабиринтов.
/* Define the format */
proc format;
value $direction
'D' = 'down'
'L' = 'left'
'R' = 'right'
'U' = 'up'
;
run;
data want;
/*Read in the maze and start/end points in (y,x) orientation*/
array maze(6,7) (
1,1,1,1,1,1,1,
1,0,0,1,1,1,1,
1,1,0,1,1,0,1,
1,1,0,1,0,0,1,
1,1,0,0,0,1,1,
1,1,1,1,1,1,1
);
array endpoints (2,2) (
2,2
3,6
);
/*Load the start point and output a row*/
x = endpoints(1,2);
y = endpoints(1,1);
output;
/*
Navigate through the maze.
Assume for the sake of simplicity that it is really more of a labyrinth,
i.e. there is only ever one valid direction in which to move,
other than the direction you just came from,
and that the end point is reachable
*/
do _n_ = 1 by 1 until(x = endpoints(2,2) and y = endpoints(2,1));
if maze(y-1,x) = 0 and direction ne 'D' then do;
direction = 'U';
y + -1;
end;
else if maze(y+1,x) = 0 and direction ne 'U' then do;
direction = 'D';
y + 1;
end;
else if maze(y,x-1) = 0 and direction ne 'R' then do;
direction = 'L';
x + -1;
end;
else if maze(y,x+1) = 0 and direction ne 'L' then do;
direction = 'R';
x + 1;
end;
output;
if _n_ > 15 then stop; /*Set a step limit in case something goes wrong*/
end;
format direction $direction.;
drop maze: endpoints:;
run;
Просьба более подробно описать, что вы пытаетесь сделать с массивом, и взглянуть на документацию для оператора массива. – user667489
Приведите пример того, как должен выглядеть ваш ожидаемый результат из заданного набора входов. Непонятно, из чего вы указали то, что ищете – DCR
Разве это «файл лабиринта» - лабиринт, где 1 - это стены, а 0 - подвижные пространства? (Если это так, ваш пример неразрешимый, если вы не можете двигаться по диагонали). Что бы вы хотели получить? Список путей от начала до конца? Укажите желаемый выходной набор данных. – Quentin