- 772 名前:デフォルトの名無しさん mailto:sage [2019/03/22(金) 12:12:43.26 ID:bmKj2SZK.net]
- >>751 Squeak Smalltalk
| fn | fn := [:str | | map range sign goal position next atEnd | map := str lines collect: [:line | line subStrings collect: #asInteger]. range := 1@1 extent: map first size @ map size. sign := (0 asPoint fourNeighbors with: #(→ ↓ ← ↑) collect: #->) as: Dictionary. goal := #★. position := 1@1. next := 2. atEnd := false. [atEnd] whileFalse: [ | found | found := position fourNeighbors detect: [:neighPos | (range containsPoint: neighPos) and: [((map at: neighPos y) at: neighPos x) = next] ] ifNone: [atEnd := true. Float nan]. (map at: position y) at: position x put: (sign at: found - position ifAbsent: goal). position := found. 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' "=> '↓→→↓ →↑↓← ↓←→↓ ★↑←←' "
|

|