[過去ログ] プログラミングのお題スレ Part13 (1002レス)
前次1-
抽出解除 必死チェッカー(本家) (べ) 自ID レス栞 あぼーん

このスレッドは過去ログ倉庫に格納されています。
次スレ検索 歴削→次スレ 栞削→次スレ 過去ログメニュー
750: 2019/03/22(金)12:12 ID:bmKj2SZK(1)調 AAS
>>746 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'

"=>
'↓→→↓
→↑↓←
↓←→↓
★↑←←' "
前次1-
スレ情報 赤レス抽出 画像レス抽出 歴の未読スレ AAサムネイル

ぬこの手 ぬこTOP 0.037s