5 edited body
source | link

Perl 5, -ap 121 bytes / 56 bytes

This 121 vytebyte solution has a uniform distribution over all valid arrangements of boxes. It tries to be somewhat efficient but still times out on TIO for size 4 or more

#!/usr/bin/perl -ap
@a=((0 x$_.$")x$_.$/)x$_."";s%0%/0(|.{@F}|(\X{@F}\X){@F})\G/+${$z="$`1$'"}++||push@a,$z;0%eg for@a;$_=$a[rand@a];$\=y/1//

Try it online!

If you don't care about uniformity it's of course easy to go shorter, e.g. this 56 bytes solution is very biased towards the origin (it probably gives more nice pictures for the motivating example though)

#!/usr/bin/perl -a
say map{\@$_[rand@;+1,$#{$_-1}];@;-$#$_.$"}@;for@;=1..$_

Try it online!

(checked for size 2 and 3 that it indeed generates all possible outputs)

Perl 5, -ap 121 bytes / 56 bytes

This 121 vyte solution has a uniform distribution over all valid arrangements of boxes. It tries to be somewhat efficient but still times out on TIO for size 4 or more

#!/usr/bin/perl -ap
@a=((0 x$_.$")x$_.$/)x$_."";s%0%/0(|.{@F}|(\X{@F}\X){@F})\G/+${$z="$`1$'"}++||push@a,$z;0%eg for@a;$_=$a[rand@a];$\=y/1//

Try it online!

If you don't care about uniformity it's of course easy to go shorter, e.g. this 56 bytes solution is very biased towards the origin (it probably gives more nice pictures for the motivating example though)

#!/usr/bin/perl -a
say map{\@$_[rand@;+1,$#{$_-1}];@;-$#$_.$"}@;for@;=1..$_

Try it online!

(checked for size 2 and 3 that it indeed generates all possible outputs)

Perl 5, -ap 121 bytes / 56 bytes

This 121 byte solution has a uniform distribution over all valid arrangements of boxes. It tries to be somewhat efficient but still times out on TIO for size 4 or more

#!/usr/bin/perl -ap
@a=((0 x$_.$")x$_.$/)x$_."";s%0%/0(|.{@F}|(\X{@F}\X){@F})\G/+${$z="$`1$'"}++||push@a,$z;0%eg for@a;$_=$a[rand@a];$\=y/1//

Try it online!

If you don't care about uniformity it's of course easy to go shorter, e.g. this 56 bytes solution is very biased towards the origin (it probably gives more nice pictures for the motivating example though)

#!/usr/bin/perl -a
say map{\@$_[rand@;+1,$#{$_-1}];@;-$#$_.$"}@;for@;=1..$_

Try it online!

(checked for size 2 and 3 that it indeed generates all possible outputs)

4 deleted 68 characters in body
source | link

Perl 5, -ap 121 bytes / 56 bytes

Distribution isThis 121 vyte solution has a uniform distribution over all valid arrangements of boxes. TriesIt tries to be somewhat efficient but still times out on TIO for size 4 or more

#!/usr/bin/perl -ap
@a=((0 x$_.$")x$_.$/)x$_."";s%0%/0(|.{@F}|(\X{@F}\X){@F})\G/+${$z="$`1$'"}++||push@a,$z;0%eg for@a;$_=$a[rand@a];$\=y/1//

Try it online!

If you don't care about uniformity it's of course easy to go shorter, e.g. this 7356 bytes solution is extremelyvery biased towards the origin (it probably gives more nice pictures for the motivating example though)

#!/usr/bin/perl -a
@a=($_)x$_;map{$;+=$_=0|randsay 1+($_<$'?$_:$'//$_)map{\@$_[rand@;+1,// for@a;say"@a"$#{$_-1}@a;say$];@;-$#$_.$"}@;for@;=1..$_

Try it online!Try it online!

(checked for size 2 and 3 that it indeed generates all possible outputs)

Perl 5, -ap 121 bytes

Distribution is uniform over all valid arrangements of boxes. Tries to be somewhat efficient but still times out on TIO for size 4 or more

#!/usr/bin/perl -ap
@a=((0 x$_.$")x$_.$/)x$_."";s%0%/0(|.{@F}|(\X{@F}\X){@F})\G/+${$z="$`1$'"}++||push@a,$z;0%eg for@a;$_=$a[rand@a];$\=y/1//

Try it online!

If you don't care about uniformity it's of course easy to go shorter, e.g. this 73 bytes solution is extremely biased towards the origin (it probably gives more nice pictures for the motivating example though)

#!/usr/bin/perl -a
@a=($_)x$_;map{$;+=$_=0|rand 1+($_<$'?$_:$'//$_),// for@a;say"@a"}@a;say$

Try it online!

Perl 5, -ap 121 bytes / 56 bytes

This 121 vyte solution has a uniform distribution over all valid arrangements of boxes. It tries to be somewhat efficient but still times out on TIO for size 4 or more

#!/usr/bin/perl -ap
@a=((0 x$_.$")x$_.$/)x$_."";s%0%/0(|.{@F}|(\X{@F}\X){@F})\G/+${$z="$`1$'"}++||push@a,$z;0%eg for@a;$_=$a[rand@a];$\=y/1//

Try it online!

If you don't care about uniformity it's of course easy to go shorter, e.g. this 56 bytes solution is very biased towards the origin (it probably gives more nice pictures for the motivating example though)

#!/usr/bin/perl -a
say map{\@$_[rand@;+1,$#{$_-1}];@;-$#$_.$"}@;for@;=1..$_

Try it online!

(checked for size 2 and 3 that it indeed generates all possible outputs)

3 added 31 characters in body
source | link

Perl 5, -ap 121 bytes

Distribution is uniform over all valid arrangements of boxes. Tries to be somewhat efficient but still times out on TIO for size 4 or more

#!/usr/bin/perl -ap
@a=((0 x$_.$")x$_.$/)x$_."";s%0%/0(|.{@F}|(\X{@F}\X){@F})\G/+${$z="$`1$'"}++||push@a,$z;0%eg for@a;$_=$a[rand@a];$\=y/1//

Try it online!

If you don't care about uniformity it's of course easy to go shorter, e.g. this 7573 bytes solution is extremely biased towards the origin (it probably gives more nice pictures for the motivating example though)

#!/usr/bin/perl -a
$z=@a=@a=($_)x$_;map{$z=map$;+=$z=$_=0|rand$;+=$_=0|rand 1+($_<$z$_<$'?$_:$z$'//$_),@a;say"@a"// for@a;say"@a"}@a;say$

Try it online!Try it online!

Perl 5, -ap 121 bytes

Distribution is uniform over all valid arrangements of boxes. Tries to be somewhat efficient but still times out on TIO for size 4 or more

#!/usr/bin/perl -ap
@a=((0 x$_.$")x$_.$/)x$_."";s%0%/0(|.{@F}|(\X{@F}\X){@F})\G/+${$z="$`1$'"}++||push@a,$z;0%eg for@a;$_=$a[rand@a];$\=y/1//

Try it online!

If you don't care about uniformity it's of course easy to go shorter, e.g. this 75 bytes solution is extremely biased towards the origin (it probably gives more nice pictures for the motivating example though)

#!/usr/bin/perl -a
$z=@a=($_)x$_;map{$z=map$;+=$z=$_=0|rand 1+($_<$z?$_:$z),@a;say"@a"}@a;say$

Try it online!

Perl 5, -ap 121 bytes

Distribution is uniform over all valid arrangements of boxes. Tries to be somewhat efficient but still times out on TIO for size 4 or more

#!/usr/bin/perl -ap
@a=((0 x$_.$")x$_.$/)x$_."";s%0%/0(|.{@F}|(\X{@F}\X){@F})\G/+${$z="$`1$'"}++||push@a,$z;0%eg for@a;$_=$a[rand@a];$\=y/1//

Try it online!

If you don't care about uniformity it's of course easy to go shorter, e.g. this 73 bytes solution is extremely biased towards the origin (it probably gives more nice pictures for the motivating example though)

#!/usr/bin/perl -a
@a=($_)x$_;map{$;+=$_=0|rand 1+($_<$'?$_:$'//$_),// for@a;say"@a"}@a;say$

Try it online!

2 added 544 characters in body
source | link
1
source | link