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.

More context can be found in the book 10 print.

  • \$\begingroup\$ Another output example would probably be useful. And I expect the title should be "one liner". \$\endgroup\$ Sep 25, 2015 at 0:06
  • \$\begingroup\$ Will the input maze always be a rectangle? Could you should a larger example so we can see the spacing? \$\endgroup\$
    – xnor
    Sep 25, 2015 at 0:06
  • 2
    \$\begingroup\$ 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? \$\endgroup\$
    – Doorknob
    Sep 25, 2015 at 0:08
  • 2
    \$\begingroup\$ Using stdin and stdout is obligatory if possible, otherwise "the closest equivalent." Are there reasons to weaken the newline-assumption? \$\endgroup\$ Sep 25, 2015 at 0:13
  • 1
    \$\begingroup\$ Related: codegolf.stackexchange.com/q/37390/194 , codegolf.stackexchange.com/q/21730/194 \$\endgroup\$ Sep 25, 2015 at 6:26

3 Answers 3


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...).

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...

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
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`


  o=Array(z=(w+h+1)*2).fill(' ').map(x=>Array(z).fill(x)),
    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]='#';


<pre id=O></pre>


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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