GolfScript, 90 bytes
~[[[1.]]]\({..[[{{(\{)}%+}%1,1ドル,ドル-=}%[1,]@0=+{1+}%]zip{{(\.,/*~}%.,.rand@=+}:^%]\+}*0=^(;`
This is an adaptation of my (simpler) partition counting code partition counting code which instead of merely tracking a count tracks both a count and a uniformly selected one of the counted elements.
Side-by-side comparison of the two:
~[[[1.]]]\({..[[{{(\{)}%+}%1,1ドル,ドル-=}%[1,]@0=+{1+}%]zip{{(\.,/*~}%.,.rand@=+}:^%]\+}*0=^(;`
[[ 1 ]]\({..[[{ 1,1ドル,ドル-=}% 0 @0=+ ]zip{{+}* }:^%]\+}*0=^
Differences:
- The initial
~is because this is a program rather than a snippet. - The
[1.]replacing1corresponds to the change in what's tracked. - The additional
{(\{)}%+}%increments each element in that partition, and the{1+}%adds1to the partition. 0becomes[0](golfed to1,) as part of the change in what's tracked, but because it needs to remain an array when prepended to another one it needs the extra[ ].- The simple sum
{+}*becomes a weighted selection from the partitions, combined with a summing of their count. - The
(;`removes the count from the output and puts the partition into a nice format.
Test framework
;7000,{;
'5'
~[[[1.]]]\({..[[{{(\{)}%+}%1,1ドル,ドル-=}%[1,]@0=+{1+}%]zip{{(\.,/*~}%.,.rand@=+}:^%]\+}*0=^(;`
}%
:RESULTS
.&${
RESULTS.[2$]--,' '\n
}/
Tweak the initial 7000 if you want to run a different number of trials. Note that this is far too slow for an online demo.
GolfScript, 90 bytes
~[[[1.]]]\({..[[{{(\{)}%+}%1,1ドル,ドル-=}%[1,]@0=+{1+}%]zip{{(\.,/*~}%.,.rand@=+}:^%]\+}*0=^(;`
This is an adaptation of my (simpler) partition counting code which instead of merely tracking a count tracks both a count and a uniformly selected one of the counted elements.
Side-by-side comparison of the two:
~[[[1.]]]\({..[[{{(\{)}%+}%1,1ドル,ドル-=}%[1,]@0=+{1+}%]zip{{(\.,/*~}%.,.rand@=+}:^%]\+}*0=^(;`
[[ 1 ]]\({..[[{ 1,1ドル,ドル-=}% 0 @0=+ ]zip{{+}* }:^%]\+}*0=^
Differences:
- The initial
~is because this is a program rather than a snippet. - The
[1.]replacing1corresponds to the change in what's tracked. - The additional
{(\{)}%+}%increments each element in that partition, and the{1+}%adds1to the partition. 0becomes[0](golfed to1,) as part of the change in what's tracked, but because it needs to remain an array when prepended to another one it needs the extra[ ].- The simple sum
{+}*becomes a weighted selection from the partitions, combined with a summing of their count. - The
(;`removes the count from the output and puts the partition into a nice format.
Test framework
;7000,{;
'5'
~[[[1.]]]\({..[[{{(\{)}%+}%1,1ドル,ドル-=}%[1,]@0=+{1+}%]zip{{(\.,/*~}%.,.rand@=+}:^%]\+}*0=^(;`
}%
:RESULTS
.&${
RESULTS.[2$]--,' '\n
}/
Tweak the initial 7000 if you want to run a different number of trials. Note that this is far too slow for an online demo.
GolfScript, 90 bytes
~[[[1.]]]\({..[[{{(\{)}%+}%1,1ドル,ドル-=}%[1,]@0=+{1+}%]zip{{(\.,/*~}%.,.rand@=+}:^%]\+}*0=^(;`
This is an adaptation of my (simpler) partition counting code which instead of merely tracking a count tracks both a count and a uniformly selected one of the counted elements.
Side-by-side comparison of the two:
~[[[1.]]]\({..[[{{(\{)}%+}%1,1ドル,ドル-=}%[1,]@0=+{1+}%]zip{{(\.,/*~}%.,.rand@=+}:^%]\+}*0=^(;`
[[ 1 ]]\({..[[{ 1,1ドル,ドル-=}% 0 @0=+ ]zip{{+}* }:^%]\+}*0=^
Differences:
- The initial
~is because this is a program rather than a snippet. - The
[1.]replacing1corresponds to the change in what's tracked. - The additional
{(\{)}%+}%increments each element in that partition, and the{1+}%adds1to the partition. 0becomes[0](golfed to1,) as part of the change in what's tracked, but because it needs to remain an array when prepended to another one it needs the extra[ ].- The simple sum
{+}*becomes a weighted selection from the partitions, combined with a summing of their count. - The
(;`removes the count from the output and puts the partition into a nice format.
Test framework
;7000,{;
'5'
~[[[1.]]]\({..[[{{(\{)}%+}%1,1ドル,ドル-=}%[1,]@0=+{1+}%]zip{{(\.,/*~}%.,.rand@=+}:^%]\+}*0=^(;`
}%
:RESULTS
.&${
RESULTS.[2$]--,' '\n
}/
Tweak the initial 7000 if you want to run a different number of trials. Note that this is far too slow for an online demo.
GolfScript, 90 bytes
~[[[1.]]]\({..[[{{(\{)}%+}%1,1ドル,ドル-=}%[1,]@0=+{1+}%]zip{{(\.,/*~}%.,.rand@=+}:^%]\+}*0=^(;`
This is an adaptation of my (simpler) partition counting code which instead of merely tracking a count tracks both a count and a uniformly selected one of the counted elements.
Side-by-side comparison of the two:
~[[[1.]]]\({..[[{{(\{)}%+}%1,1ドル,ドル-=}%[1,]@0=+{1+}%]zip{{(\.,/*~}%.,.rand@=+}:^%]\+}*0=^(;`
[[ 1 ]]\({..[[{ 1,1ドル,ドル-=}% 0 @0=+ ]zip{{+}* }:^%]\+}*0=^
Differences:
- The initial
~is because this is a program rather than a snippet. - The
[1.]replacing1corresponds to the change in what's tracked. - The additional
{(\{)}%+}%increments each element in that partition, and the{1+}%adds1to the partition. 0becomes[0](golfed to1,) as part of the change in what's tracked, but because it needs to remain an array when prepended to another one it needs the extra[ ].- The simple sum
{+}*becomes a weighted selection from the partitions, combined with a summing of their count. - The
(;`removes the count from the output and puts the partition into a nice format.
Test framework
;7000,{;
'5'
~[[[1.]]]\({..[[{{(\{)}%+}%1,1ドル,ドル-=}%[1,]@0=+{1+}%]zip{{(\.,/*~}%.,.rand@=+}:^%]\+}*0=^(;`
}%
:RESULTS
.&${
RESULTS.[2$]--,' '\n
}/
Tweak the initial 7000 if you want to run a different number of trials. Note that this is far too slow for an online demo.