# Maze generating one liner

The famous C64 basic one liner

10 PRINT CHR\$(205.5+RND(1)); : GOTO 10

prints a maze of slashes and backslashes.

\\/\\\//\/\////\\/\/
\/\///\\///////\//\/
/\\\//\//\////\\//\\
\////\//\//\/\\\\\\/
/\/\\///\\\\/\\\\/\\
\/\//\\\\\\//\/\////
/\//\\///\/\///\////
\/\\\//\\/\\\//\\/\/
//////\\/\\/\/\/\///
\\/\/\\////\/\/\\/\/

Read in such maze made of diagonal walls from stdin and print out the same maze with horizontal and vertical walls consisting of the wall character "#"

For example the small maze

/\\
\\/
///

translates to

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

#####

To be precise, each isolated wall segment has the length of five characters, adjacent wall segments share a corner. Moving a character to the right/left/top/down in the matrix of slashes and backslashes corresponds to a diagonal translation by 2 characters in vertical and 2 characters in horizontal direction in the #-matrix.

• Another output example would probably be useful. And I expect the title should be "one liner". – Calvin's Hobbies Sep 25 '15 at 0:06
• Will the input maze always be a rectangle? Could you should a larger example so we can see the spacing? – xnor Sep 25 '15 at 0:06
• Welcome to Programming Puzzles & Code Golf Stack Exchange! Great first challenge, but a few things: can input/output be something other than STDIN/STDOUT (ex. as a function argument and return value)? Can lines be separated via a character other than newlines? – Doorknob Sep 25 '15 at 0:08
• Using stdin and stdout is obligatory if possible, otherwise "the closest equivalent." Are there reasons to weaken the newline-assumption? – mschauer Sep 25 '15 at 0:13
• – Peter Taylor Sep 25 '15 at 6:26

# Python 3, 226 224 bytes

My first Python golf, so probably very sub-optimal. It produces a whole lot of trailing whitespace, but there are no preceding newlines, and at most two preceding spaces. The input needs to be given by hand from command line (maybe someone knows a shorter way to get multiline input in Python...).

e,z,s=enumerate,'0',list(iter(input,""))
p=''.join(s)*5
r=[len(p)*[' ']for _ in p]
for y,l in e(s):
for x,c in e(l):
for i in range(-2,3):r[2*(x+y+(s>[z]))+i*(c>z)][2*(x+len(s)-y)+i*(c<z)]='#'
for l in r:print(''.join(l))

The idea is to initialize a huge array of spaces r, then iterate through the input and replace the spaces with # as needed, and finally print the whole array. A trick I used is to compare characters to z = '0' instead of testing equality to '/' or '\', which saves a bunch of bytes.

# Julia, 258 bytes

A functional solution...

q(i,j)=fld(i-1,j)
n,^ =A[].(3),q
f(i,j)=try A[1+i^5][1+j^5]<'0'?(i+j)%5==1:(i-j)%5==0catch 0end
h(i,j)=f(i+i^4,j)|f(i+(i-1)^4,j)
g(i,j)=h(i,j+j^4)|h(i,j+(j-1)^4)
for i=1:6length(A),j=-n-5:2n;print(" #"[1+g(i-j,i+j)],j==2n?"\n":"")end

In order of appearance: f covers '/' and '\' by their 5*5 bit patters, h folds every fifth and following line into a single line (recall "adjacent wall segments share a corner") and g does the same for the columns. Finally, i-j,i+j rotates the picture.

# JavaScript (ES6), 258

A function with the maze as a parameter, returning the output.

Unsure if it's valid, due to the input/output rules (it was fun anyway)

f=m=>([...m].map(c=>{if(c<' ')x=sx-=2,y=sy+=2;else for(x+=2,y+=2,d=c>'0',i=y-3*d,j=x-3*!d,c=5;c--;)o[i+=d][j+=!d]='#';},w=m.search
,h=m.match(/\n/g).length,sy=y=0,sx=x=h*2,o=Array(z=(w+h+1)*2).fill(' ').map(x=>Array(z).fill(x))),o.map(r=>r.join).join
)

// LESS GOLFED

U=m=>(
w=m.search\n,
h=m.match(/\n/g).length,
o=Array(z=(w+h+1)*2).fill(' ').map(x=>Array(z).fill(x)),
sy=y=0,
sx=x=h*2,
[...m].forEach(c=>{
if(c<' ')x=sx-=2,y=sy+=2
else for(x+=2,y+=2,d=c>'0',i=y-3*d,j=x-3*!d,c=5;c--;)o[i+=d][j+=!d]='#';
}),
o.map(r=>r.join).join\n
)

// TEST
out=x=>O.innerHTML+=x+'\n'

test=\\\\/\\\\\\//\\/\\////\\\\/\\/
\\/\\///\\\\///////\\//\\/
/\\\\\\//\\//\\////\\\\//\\\\
\\////\\//\\//\\/\\\\\\\\\\\\/
/\\/\\\\///\\\\\\\\/\\\\\\\\/\\\\
\\/\\//\\\\\\\\\\\\//\\/\\////
/\\//\\\\///\\/\\///\\////
\\/\\\\\\//\\\\/\\\\\\//\\\\/\\/
//////\\\\/\\\\/\\/\\/\\///
\\\\/\\/\\\\////\\/\\/\\\\/\\/
out(test),out(f(test))
<pre id=O></pre>