Comment detail

全ての組み合わせ (Nested Flatten)
Squeak Smalltalk で。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
| input results gen |
input := #((0 1) 'ab' (Foo Bar)).
results := OrderedCollection new.
gen := input reversed
    inject: [:arr | results add: arr]
    into: [:block :colln |
        [:arr | colln do: [:ea | block value: arr, {ea}]] fixTemps].
gen value: #().
^results asArray

"=> #((0 $a Foo) (0 $a Bar) (0 $b Foo) (0 $b Bar)
   (1 $a Foo) (1 $a Bar) (1 $b Foo) (1 $b Bar)) "
ether さんの #2152 の簡潔さに感心しつつ、それをヒントにして同様のことを Squeak Smalltalk で。
1
2
3
4
| input |
input := #((0 1) 'ab' (foo bar)).
^input reversed inject: #(()) into: [:arrs :colln |
    colln inject: #() into: [:rs :elem | rs, (arrs collect: [:arr | {elem}, arr])]]

Index

Feed

Other

Link

Pathtraq

loading...