【激突】関数型言語 VS オブジェクト指向言語2
レス数が900を超えています。1000を超えると表示できなくなるよ。
0932デフォルトの名無しさん
2012/05/25(金) 15:16:47.49>>782や>>799と見比べて、関数型でMultiSet(Bag)が使えてもぜんぜん嬉しくないのはよく分かった。
| M N cards bag replicate randoms |
M := 1000.
N := 10.
cards := 1 to: N.
replicate := [:n :x | Array new: n withAll: x].
randoms := [:g | (g next: N*10) * 2147483647 truncated].
bag := (replicate value: M value: Random new) inject: Bag new into: [:b :g |
b add: (((randoms value: g) inject: {Bag new} into: [:xs :n |
xs, {xs last copy add: n \\ N + 1; yourself}])
detect: [:xs | xs includesAllOf: cards]) size; yourself].
^{bag min. bag max. bag sortedCounts first} "=> {12 . 85 . 56->23} "
レス数が900を超えています。1000を超えると表示できなくなるよ。