I'd like to plot lattice paths like RUURUD
where R
is a step to the right, U
is a step above and D
is a diagonal step. But I have 2 problems
1)
The way i'm trying to plot a path (which seems horrible to me) is using Graph[Line[{p1,p2,...pn}]]
function.
I'm trying to convert the path to points in this way:
LetraMap := <|"R" -> {1,0}, "U" -> {0,1}, "D" ->{1,1} |>;
LetraACoordenada[palabra_,1] := If[KeyExistsQ[LetraMap, StringTake[palabra, 1]],LetraMap[StringTake [palabra,1]],{0,0}]
LetraACoordenada[palabra_, n_] := LetraACoordenada[palabra,n-1] + LetraMap[ StringTake @@{palabra,n} ]
But when I try to define it returns:
SetDelayed: The value for the key palabra_ does not exist
I also tried:
PalabraDiagonalACoordenada = Function[{palabraDiagonal},
coordenadas = {{0,0}};
Do[
AppendTo[coordenadas,coordenadas[[i]] + LetraACoordenada @ StringTake @@ {palabraDiagonal, i}];
,{i,StringLength @ palabraDiagonal}
];
Print["xd"];
Return[coordenadas];
]
But when I execute
PalabraDiagonalACoordenadas["URUURUD"]
it simply does not returns nothing (I awaited for a long time haha) not even the xd
I dont know what's the error with this functions or if is it a easier/mathematical (like pythonic hahah) way to do this.
2) I'd also like to make a beautiful graph like
and nice animation like
I've tried with https://mathematica.stackexchange.com/a/112411/91847 solution (GridGrpah
) but it doesn't connect diagonal lines (it actually make sense because diagonal vertices does not exists).
thanks in advance