2
\$\begingroup\$

Print the ASCII version of a random grid.

################################################################################
#    #   #  #    #   #   #     #     #   #  #    #   #     #   #   #   #  #   # 
#    #   #  #    #   #   #     #     #   #  #    #   #     #   #   #   #  #   # 
#    #   #############   #     #     #   #  #    #   #     #   #   #   #  #   # 
##########   #   #   #####################  #    #   #     #   #####   ######## 
#    #   #   #   #   #   #   #   #       #######################   #####   #  ##
#    #   #   #   #   #   #   #   #       #  #   #     #   #    #   #   #   #  # 
#    #   #   #   #   #   #####   #       #  #   #     #   #    #   #   #########
##########################   #######################################   #    #  #
#    #    #   #   #  #   #   #    #      #   #   #   #   #     #   #####    #  #
#    #    #   #   #  #   #   #    #      #   #   #   #   #     #   #   #    ####
###############   #  #   #####    #      #   #   #   #   #     #   #   #    #  #
#    #   #    ########   #   ###################################   #   ######  #
#    #   #    #   #  #####   #     #    #  #    #   #   #      #########    #  #
######   #    #   #  #   #   #     #    #  #    #   #   #      #   #   #    #  #

The picture should illustrate the constraints:

  • # is solid, is empty.
  • Print 80 columns, at least 80 rows.
  • On the first and last columns and first and last rows there is some freedom, but at least the printout must be extendible to a legal grid.
  • Boxes contain empty areas between 1x1 and 7x7.
  • Constraints: Boxes are rectangular, no lonely corners (1), no empty boxes (2), no broken lines(3) or gaps (4), when in doubt refer to the image above.
  • A grid is considered "random", if the first 80 rows contain: 1.) 60 unique rows and 60 unique columns. 2.) At least one box with inner area of size (2, 2), (3, 2), (4, 2), (5, 2), (2, 3), (3, 3), (4, 3), (5, 3), (2, 4), (3, 4), (4, 4), (5, 4), (2, 5), (3, 5), (4, 5), (5, 5) each. You can verify the randomness and some constraints with this julia script.
  • The program should nondeterministically produce a minimum number of 1000 grids fulfilling the constraints with different first 80 rows, where rotations, circular shifts and reflections counted as same and the majority of produced grids should be "random" as specified above.
    #####4########################
    #                #   #    #    
    #    #       #   #   #    3    
    #    #       #########   #    
    #########1   #   #   #########
    #    #   #   #   ##2##   #   #
    #    #   #   #   #####   #   #
    #    #   #   #   #   #   #####

Code golf!

\$\endgroup\$
  • 7
    \$\begingroup\$ You need to specify exactly what you mean by random. "Do not systematically produce homogeneous rows of boxes..." also needs to be made objective. \$\endgroup\$ – xnor Nov 10 '19 at 0:28
  • \$\begingroup\$ @xnor I created a rule specifying "randomness". \$\endgroup\$ – mschauer Nov 10 '19 at 11:22
  • \$\begingroup\$ You say "at least 80 rows" but - specifically - "80 columns". Is that indended? Also, your program gives a warning for more than 80 rows. \$\endgroup\$ – dzaima Nov 10 '19 at 12:39
  • \$\begingroup\$ The program expects you to submit the first 80 rows of your output, the remainder can be anything, as long as it is a valid labyrinth. \$\endgroup\$ – mschauer Nov 10 '19 at 13:03
  • \$\begingroup\$ I added a requirement discouraging to encode a hand drawn valid grid as 80*80 bit number ;-) \$\endgroup\$ – mschauer Nov 10 '19 at 13:13
1
\$\begingroup\$

Julia, 254 bytes

Not very golfed, just to keep it going;

l=length
function f(M,r,s)
l(r)<7&&return l(s)>6&&g(M,r,s)
h,j=rand([f,g],2)
a,c=extrema(r)
b=rand(a+1:c-1)
M[b,s].=2
h(M,b+1:c,s)
j(M,a:b-1,s)
end
g(M,r,s)=f(M',s,r)
n=80
M=fill(1,n,n)
f(M,1:n,1:n)
for i∈1:n
print.(getindex.(" #",M[i,:]))
println()
end

Verification, try it yourself

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.