#!/bin/sed -f
# Author: Laurent Le Brun <llb [at] fr.fm>

s/.*/############\
#A  #   #B #\
#     # #  #\
# # ### #  #\
# #   #    #\
#   #   #  #\
############/

## Fill matrix ##

s/A/0/g
:fill
y/0123456789a/123456789a0/
s/1 /10/g
s/ 1/01/g
s/1\(.\{12\}\) /1\10/g
s/ \(.\{12\}\)1/0\11/g

# path found ?
/0B/ b all
/B0/ b all
/B\(.\{12\}\)0/ b all
/0\(.\{12\}\)B/ b all
t fill

# no :(
i\
  No path was found.
d  
q  

## Get path ##

:all
# just follow the numbers !
# uncomment next line for debugging
# p
s/B/X/g
:est

/0X/ {
    s/0X/PX/
    b anana
}  
/X0/ {
    s/X0/XP/
    b anana
}  
/X\(.\{12\}\)0/ {
    s/X\(.\{12\}\)0/X\1P/
    b anana
}  
/0\(.\{12\}\)X/ {
    s/0\(.\{12\}\)X/P\1X/
    b anana
}  

# The end.
# Clean the output.
s/[^ X*#\n]/ /g
q  

# just some updates
:anana
s/X/*/
s/P/X/
y/0123456789a/a0123456789/
t est

### colorized by sedsed, a SED script debugger/indenter/tokenizer/HTMLizer
### original script: http://laurent.le-brun.eu/pub/path.sed