[表示 : 全て 最新50 1-99 101- 201- 301- 401- 501- 601- 701- 801- 901- 1001- 2ch.scのread.cgiへ]
Update time : 06/28 06:35 / Filesize : 332 KB / Number-of Response : 1028
[このスレッドの書き込みを削除する]
[+板 最近立ったスレ&熱いスレ一覧 : +板 最近立ったスレ/記者別一覧] [類似スレッド一覧]


↑キャッシュ検索、類似スレ動作を修正しました、ご迷惑をお掛けしました

プログラミングのお題スレ Part13



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'

"=>
'↓→→↓
→↑↓←
↓←→↓
★↑←←' "






[ 続きを読む ] / [ 携帯版 ]

全部読む 前100 次100 最新50 [ このスレをブックマーク! 携帯に送る ] 2chのread.cgiへ
[+板 最近立ったスレ&熱いスレ一覧 : +板 最近立ったスレ/記者別一覧](;´∀`)<332KB

read.cgi ver5.27 [feat.BBS2 +1.6] / e.0.2 (02/09/03) / eucaly.net products.
担当:undef