This comment is reply for 1399 sumim: Squeak Smalltalk で。(マップの通り抜け). Go to thread root.
sumim #1407(2007/07/24 10:03 GMT) [ Smalltalk ] Rating0/0=0.00
#1399 で、 map at: 1 at: cIdx put: $*. は、不要でした(^_^;)。 改めまして、$* でなぞる版も。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| map width height mapString mapFilename queue | mapFilename := 'map.txt'. mapString := (FileStream fileNamed: mapFilename) contents. width := (mapString indexOf: Character cr) - 1. height := mapString size + 1 // (width + 1). map := Matrix rows: height columns: width contents: (mapString copyWithout: Character cr). queue := OrderedCollection new. 1 to: width do: [:y | (map at: 1 at: y) = $+ ifTrue: [queue add: 1@y]]. [queue notEmpty] whileTrue: [ | position | position := queue removeFirst. map at: position x at: position y put: $*. {-1@0. 0@-1. 1@0. 0@1} do: [:delta | | next | next := position + delta. (map at: next x at: next y ifInvalid: [nil]) = $+ ifTrue: [ map at: next x at: next y put: $*. queue add: next]]]. ^(map atRow: height) includes: $*
Rating0/0=0.00-0+
[ reply ]
sumim
#1407()
[
Smalltalk
]
Rating0/0=0.00
| map width height mapString mapFilename queue | mapFilename := 'map.txt'. mapString := (FileStream fileNamed: mapFilename) contents. width := (mapString indexOf: Character cr) - 1. height := mapString size + 1 // (width + 1). map := Matrix rows: height columns: width contents: (mapString copyWithout: Character cr). queue := OrderedCollection new. 1 to: width do: [:y | (map at: 1 at: y) = $+ ifTrue: [queue add: 1@y]]. [queue notEmpty] whileTrue: [ | position | position := queue removeFirst. map at: position x at: position y put: $*. {-1@0. 0@-1. 1@0. 0@1} do: [:delta | | next | next := position + delta. (map at: next x at: next y ifInvalid: [nil]) = $+ ifTrue: [ map at: next x at: next y put: $*. queue add: next]]]. ^(map atRow: height) includes: $*Rating0/0=0.00-0+