Comment detail

LL Golf Hole 4 - 文章から単語の索引を作る (Nested Flatten)

Squeak Smalltalk で。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
| dict stream delimiters lineCount |
dict := Dictionary new.
stream := HTTPSocket httpGet: 'http://www.gnu.org/licenses/gpl.txt'.
delimiters := Character allCharacters reject: [:each | each isLetter].
lineCount := 0.
[stream atEnd] whileFalse: [
    lineCount := lineCount + 1.
    ((stream upTo: Character lf) subStrings: delimiters) do: [:word | 
        | lines |
        lines := dict at: word ifAbsentPut: [OrderedCollection new].
        lines add: lineCount]].
^dict

Index

Feed

Other

Link

Pathtraq

loading...