# Check adjacent cells
for ((i = 0; i < 4; i++)); do
local next_row=$((row + delta_row[i]))
local next_col=$((col + delta_col[i]))
# Check if the next cell is valid
if [ $next_row -ge 0 ] && [ $next_row -lt $rows ] && [ $next_col -ge 0 ] && [ $next_col -lt $cols ] && [ ${labyrinth[$next_row,$next_col]} -eq 1 ] && [ ${visited[$next_row,$next_col]} -eq 0 ]; then
explore $next_row $next_col
fi
done
}
# Main function
main() {
# Define the delta for movement (up, down, left, right)
delta_row=(-1 1 0 0)
delta_col=(0 0 -1 1)
# Define the labyrinth association table (1 represents pathway)
labyrinth=(
(1 0 1 1 1)
(1 1 1 0 1)
(0 0 0 1 1)
(1 1 1 1 0)
(1 0 1 0 1)
)
rows=${#labyrinth[@]}
cols=${#labyrinth[0]}
# Declare an associative array to keep track of visited cells
declare -A visited
# Start exploring from the entrance (side of the table)
for ((i = 0; i < $rows; i++)); do
if [ ${labyrinth[$i,0]} -eq 1 ]; then
explore $i 0
fi
done
echo "No exit found."
exit 1
}
main
Replies to Untitled
Title |
Name |
Language |
UNIX |
When |
Re: Untitled |
g |
text |
1715498432 |
8 Months ago. |
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}