Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

GolfScript, 90 bytes

~[[[1.]]]\({..[[{{(\{)}%+}%1,1ドル,ドル-=}%[1,]@0=+{1+}%]zip{{(\.,/*~}%.,.rand@=+}:^%]\+}*0=^(;`

Online demo

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.] replacing 1 corresponds to the change in what's tracked.
  • The additional {(\{)}%+}% increments each element in that partition, and the {1+}% adds 1 to the partition.
  • 0 becomes [0] (golfed to 1,) 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=^(;`

Online demo

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.] replacing 1 corresponds to the change in what's tracked.
  • The additional {(\{)}%+}% increments each element in that partition, and the {1+}% adds 1 to the partition.
  • 0 becomes [0] (golfed to 1,) 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=^(;`

Online demo

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.] replacing 1 corresponds to the change in what's tracked.
  • The additional {(\{)}%+}% increments each element in that partition, and the {1+}% adds 1 to the partition.
  • 0 becomes [0] (golfed to 1,) 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.

Source Link
Peter Taylor
  • 43.4k
  • 4
  • 72
  • 179

GolfScript, 90 bytes

~[[[1.]]]\({..[[{{(\{)}%+}%1,1ドル,ドル-=}%[1,]@0=+{1+}%]zip{{(\.,/*~}%.,.rand@=+}:^%]\+}*0=^(;`

Online demo

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.] replacing 1 corresponds to the change in what's tracked.
  • The additional {(\{)}%+}% increments each element in that partition, and the {1+}% adds 1 to the partition.
  • 0 becomes [0] (golfed to 1,) 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.

AltStyle によって変換されたページ (->オリジナル) /