let me include my matlab version
MATLAB 266 (258 b)
function d=p(V,a),j=(a==1|a==numel(V)-1);if (a==0),d=0;return; end,d=(V(a)-48+10*p(V,a-1))*(V(a)<64);fprintf('%c%.*s%c%.*s',j*10,j*eval(strcat(regexprep(V,'[NP]','+'),48)),ones(99)*'_',j*10,(V(a+1)>64)*d,repmat((V(a+1)==78)*'=='+(V(a+1)==80)*'- ',[1 99]));end
input
An ascii-formatted string tailed by a space (since there is no end of chain '\0' in matlab
example V='12N13P '
output
pattern representation of the road
_________________________
============- - - - - - -
_________________________
function
the function must be called from its tail-1 (the empty character is removed)
example : p(V,numel(V)-1)