Skip to main content
deleted 118 characters in body
Source Link
Neil
  • 177.2k
  • 12
  • 74
  • 281

Charcoal, 7777 63 bytes

NθNηJ‽θ‽η+W‹LKA×θη«J‽θ‽η¿¬℅KK«≔Φ⁴℅§KVκι¿ι§2064‽ι»»UE¹¦¹FθFη«J⊗ι⊗κF›KK+P✳IKK²+NθNηJ⊗‽θ⊗‽ηP+  ¦+W‹№KA+×θη«J⊗‽θ⊗‽η¿¬℅KK«≔⌕AKV ι¿ι«P+  P✳⁻χ⊗‽ι²+

Try it online!Try it online! Link is to verbose version of code. Outputs ana whitespace-bordered ASCII grid. Explanation:

NθNη

Input the width and height.

J‽θ‽η+J⊗‽θ⊗‽ηP+  ¦+

Jump to a random position and mark it with a + surrounded with spaces. (Unfortunately Charcoal's Multiprint operator special-cases a leading + so I have to output the + separately.)

W‹LKA×θη«W‹№KA+×θη«

Repeat until w*h positions+s have been filled inoutput.

J‽θ‽ηJ⊗‽θ⊗‽η

Jump to a random position.

¿¬℅KK«

If the position is vacant,

≔Φ⁴℅§KVκι≔⌕AKV ι

find any filled neighboursneighbouring spaces,

¿ι§2064‽ι»»¿ι«

and if there is one mark its direction (choosing randomly if there are more thanat least one).

UE¹¦¹

Insert blank rows and columns to make an ASCII grid.

FθFη«

Loop over all the rows and columns., then

J⊗ι⊗κP+  P✳⁻χ⊗‽ι²+

Jump tosurround the (expanded)current position.

F›KK+

If this isn't the original + with spaces,

P✳IKK²

then draw a - or | in the appropriatea random matching direction.

+

Replace the digit with, and finally draw a + in the current position.

Charcoal, 77 bytes

NθNηJ‽θ‽η+W‹LKA×θη«J‽θ‽η¿¬℅KK«≔Φ⁴℅§KVκι¿ι§2064‽ι»»UE¹¦¹FθFη«J⊗ι⊗κF›KK+P✳IKK²+

Try it online! Link is to verbose version of code. Outputs an ASCII grid. Explanation:

NθNη

Input the width and height.

J‽θ‽η+

Jump to a random position and mark it with a +.

W‹LKA×θη«

Repeat until w*h positions have been filled in.

J‽θ‽η

Jump to a random position.

¿¬℅KK«

If the position is vacant,

≔Φ⁴℅§KVκι

find any filled neighbours,

¿ι§2064‽ι»»

and if there is one mark its direction (choosing randomly if there are more than one).

UE¹¦¹

Insert blank rows and columns to make an ASCII grid.

FθFη«

Loop over all the rows and columns.

J⊗ι⊗κ

Jump to the (expanded) position.

F›KK+

If this isn't the original +,

P✳IKK²

then draw a - or | in the appropriate direction.

+

Replace the digit with a +.

Charcoal, 77 63 bytes

NθNηJ⊗‽θ⊗‽ηP+  ¦+W‹№KA+×θη«J⊗‽θ⊗‽η¿¬℅KK«≔⌕AKV ι¿ι«P+  P✳⁻χ⊗‽ι²+

Try it online! Link is to verbose version of code. Outputs a whitespace-bordered ASCII grid. Explanation:

NθNη

Input the width and height.

J⊗‽θ⊗‽ηP+  ¦+

Jump to a random position and mark it with a + surrounded with spaces. (Unfortunately Charcoal's Multiprint operator special-cases a leading + so I have to output the + separately.)

W‹№KA+×θη«

Repeat until w*h +s have been output.

J⊗‽θ⊗‽η

Jump to a random position.

¿¬℅KK«

If the position is vacant,

≔⌕AKV ι

find any neighbouring spaces,

¿ι«

and if there is at least one, then

P+  P✳⁻χ⊗‽ι²+

surround the current position with spaces, draw a - or | in a random matching direction, and finally draw a + in the current position.

Source Link
Neil
  • 177.2k
  • 12
  • 74
  • 281

Charcoal, 77 bytes

NθNηJ‽θ‽η+W‹LKA×θη«J‽θ‽η¿¬℅KK«≔Φ⁴℅§KVκι¿ι§2064‽ι»»UE¹¦¹FθFη«J⊗ι⊗κF›KK+P✳IKK²+

Try it online! Link is to verbose version of code. Outputs an ASCII grid. Explanation:

NθNη

Input the width and height.

J‽θ‽η+

Jump to a random position and mark it with a +.

W‹LKA×θη«

Repeat until w*h positions have been filled in.

J‽θ‽η

Jump to a random position.

¿¬℅KK«

If the position is vacant,

≔Φ⁴℅§KVκι

find any filled neighbours,

¿ι§2064‽ι»»

and if there is one mark its direction (choosing randomly if there are more than one).

UE¹¦¹

Insert blank rows and columns to make an ASCII grid.

FθFη«

Loop over all the rows and columns.

J⊗ι⊗κ

Jump to the (expanded) position.

F›KK+

If this isn't the original +,

P✳IKK²

then draw a - or | in the appropriate direction.

+

Replace the digit with a +.