>>754 Squeak Smalltalk

| fn |
fn := [:str |
| map range signs sign goal position from next atEnd |
map := str lines collect: [:line | line subStrings collect: #asInteger].
range := 1@1 extent: map first size @ map size.
goal := #★. signs := #(┌ ┌ ← → └ └ ┐ ┐ ↑ ↓ ┘ ┘) readStream.
sign := Dictionary new.
0 asPoint fourNeighbors combinations: 2 atATimeDo: [:combi |
sign at: combi copy put: signs next; at: combi reversed put: signs next].
position := 1@1. from := nil. next := 2. atEnd := false.
[atEnd] whileFalse: [
| found delta |
found := position fourNeighbors detect: [:neighPos |
(range containsPoint: neighPos) and: [((map at: neighPos y) at: neighPos x) = next]
] ifNone: [atEnd := true. Float nan].
delta := found - position.
(map at: position y) at: position x put: (sign at: {from ifNil: [delta negated]. delta} ifAbsent: goal).
position := found. from := delta negated. next := next + 1].
(map collect: #join) asStringWithCr
].

fn value: '1 4 5 6
2 3 8 7
15 14 9 10
16 13 12 11' .
"=>
'↓┌→┐
└┘┌┘
┌┐└┐
★└←┘' "