ASCII Maze Rendering 3000

43

7

I don't like typing, so I draw my mazes in a very simple format:

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

Isn't it a-maze-ing? Of course, I think all mazes should look 3d, similar but not he same as this challenge, for maximum a-maze-ingness, so I (grudgingly) manually updated the maze to look like this:

+-----+     +-----------------------------+
|\     \    |\                             \
+ \     \   + \                             \
 \ \     \   \ +-----------------------+     \
  \ \     \   \|                       |\     \
   \ \     \   +-----------------------+ \     \
    \ \     \     +-----------------+   \ \     \
     \ \     \    |\                 \   \ \     \
      \ \     \   + \                 \   \ \     \
       \ \     \   \ \     +-----+     \   \ \     \
        \ \     \   \ \     \    |\     \   \ \     \
         \ \     \   \ \     \---+ \     \   \ \     \
          \ \     \   \ +-----+   \ \     \   \ \     \
           \ \     \   \|     |    \ \     \   \ \     \
            \ \     \   +-----+     \ \     \   \ \     \
             \ \     +-----------------+     \   \ \     \
              \ \                             \   \ \     \
               \ \                             \   \ \     \
                \ +-----------------------------+   \ +-----+
                 \|                             |    \|     |
                  +-----------------------------+     +-----+

Unfortunately, it's difficult to work with mazes in that format, and after all that manual typing, I don't want to just retype the original, so I need you to write a program to do the reversal for me.

Rules

  • Input will be a multiline string or character matrix consisting only of " ", "|", "\", "+", "-", and newlines.
  • Output consists of " " and "#", in the pattern described by the maze.
  • Due to my amazing maze designing skills, you can assume nothing about the structure of the maze, other than that is has a valid deconstruction.
  • In the 3d-ification, (the process you must now undo,) each # was converted to this 3x4x7 character block:
    +-----+
    |\     \
    + \     \
     \ +-----+
      \|     |
       +-----+
    
  • Adjacent blocks were joined together, like this:
    +-----+-----+
    |\     \     \
    + \     \     \
     \ +-----+-----+
      \|\     \     \
       + \     \     \
        \ +-----+-----+
         \|     |     |
          +-----+-----+
    
    but without joining lines, so it actually looks like this:
    +-----------+
    |\           \
    + \           \
     \ \           \
      \ \           \
       \ \           \
        \ +-----------+
         \|           |
          +-----------+
    
  • Concave spaces sometimes block parts of other walls.
    +-----------+
    |\           \
    + \           \
     \ \     +-----+
      \ \     \    |
       \ \     \---+
        \ +-----+
         \|     |
          +-----+
    
  • Trailing whitespace in the input or output is acceptable. (You must specify if your answer requires trailing whitespace in the input.)
  • Leading whitespace must correspond to empty spaces in the input.
  • I still don't like typing, so shortest code wins

Test cases:

Input:
+-----+     +-----------------------------+
|\     \    |\                             \
+ \     \   + \                             \
 \ \     \   \ +-----------------------+     \
  \ \     \   \|                       |\     \
   \ \     \   +-----------------------+ \     \
    \ \     \     +-----------------+   \ \     \
     \ \     \    |\                 \   \ \     \
      \ \     \   + \                 \   \ \     \
       \ \     \   \ \     +-----+     \   \ \     \
        \ \     \   \ \     \    |\     \   \ \     \
         \ \     \   \ \     \---+ \     \   \ \     \
          \ \     \   \ +-----+   \ \     \   \ \     \
           \ \     \   \|     |    \ \     \   \ \     \
            \ \     \   +-----+     \ \     \   \ \     \
             \ \     +-----------------+     \   \ \     \
              \ \                             \   \ \     \
               \ \                             \   \ \     \
                \ +-----------------------------+   \ +-----+
                 \|                             |    \|     |
                  +-----------------------------+     +-----+

Output:
# #####
#     #
# ### #
# # # #
#   # #
##### #

Input:
+-----+
|\     \
+ \     \
 \ +-----+
  \|     |
   +-----+

Output:
#

Input:
      +-----------------+
      |\                 \
      + \                 \
   +-----+     +-----+     +-----+
   |\           \    |\           \
   + \           \---+ \           \
    \ \     +-----+   \ +-----+     \
     \ \     \    |    \|     |\     \
      \ \     \---+     +-----+ \     \
       \ \     +-----+     +-----+     \
        \ \           \    |\           \
         \ \           \   + \           \
          \ +-----+     +-----+     +-----+
           \|     |\                 \    |
            +-----+ \                 \---+
                   \ +-----------------+
                    \|                 |
                     +-----------------+

Output:
 ###
## ##
#   #
## ##
 ###

Input:
+-----------------------------------------------------------------------------------------------------+
|\                                                                                                     \
+ \                                                                                                     \
 \ +-----------------------------------------------+     +-----------------------------------------+     \
  \|                                               |\     \                                        |\     \
   +-----------------------------------------------+ \     \---------------------------------------+ \     \
      +-----+     +-----------------------------+   \ \     \     +-----------------------------+   \ \     \
      |\     \    |\                             \   \ \     \    |\                             \   \ \     \
      + \     \   + \                             \   \ \     \   + \                             \   \ \     \
       \ \     \   \ +-----------+     +-----+     \   \ \     \   \ +-----------------------+     \   \ \     \
        \ \     \   \|           |\     \    |\     \   \ \     \   \|                       |\     \   \ \     \
         \ \     \   +-----------+ \     \---+ \     \   \ \     \   +-----------------------+ \     \   \ \     \
          \ \     \     +-----+   \ \     \   \ \     \   \ \     +-----------------------+   \ \     \   \ \     \
           \ \     \    |\     \   \ \     \   \ \     \   \ \                             \   \ \     \   \ \     \
            \ \     \   + \     \   \ \     \   \ \     \   \ \                             \   \ \     \   \ \     \
             \ \     \   \ +-----+   \ \     \   \ \     \   \ +-----------------------------+   \ \     \   \ \     \
              \ \     \   \|     |    \ \     \   \ \     \   \|                             |    \ \     \   \ \     \
               \ \     \   +-----+     \ \     \   \ \     \   +-----------------------------+     \ \     \   \ \     \
                \ \     +-----------+   \ \     \   \ \     +-----------------------------------+   \ \     \   \ \     \
                 \ \                 \   \ \     \   \ \                                         \   \ \     \   \ \     \
                  \ \                 \   \ \     \   \ \                                         \   \ \     \   \ \     \
                   \ \     +-----------+   \ \     \   \ \     +-----------------------+     +-----+   \ \     \   \ \     \
                    \ \     \          |    \ \     \   \ \     \                      |\     \    |    \ \     \   \ \     \
                     \ \     \---------+     \ \     \   \ \     \---------------------+ \     \---+     \ \     \   \ \     \
                      \ \     \     +-----------+     \   \ \     \     +-----------+   \ \     \     +-----+     \   \ +-----+
                       \ \     \    |\                 \   \ \     \    |\           \   \ \     \    |\           \   \|     | 
                        \ \     \   + \                 \   \ \     \   + \           \   \ \     \   + \           \   +-----+  
                         \ \     \   \ +-----------------+   \ \     \   \ \           \   \ +-----+   \ +-----+     \            
                          \ \     \   \|                 |    \ \     \   \ \           \   \|     |    \|     |\     \            
                           \ \     \   +-----------------+     \ \     \   \ \           \   +-----+     +-----+ \     \            
                            \ \     +-----------------------------+     +-----+           +-----------------------+     +-----------+
                             \ \                                                                                                     \
                              \ \                                                                                                     \
                               \ +-----------------------------------------------------------------------------------------------------+
                                \|                                                                                                     | 
                                 +-----------------------------------------------------------------------------------------------------+  

Output:
#################
        #       #
# ##### # ##### #
#   # # #     # #
# # # # ##### # #
#   # #       # # 
### # ####### # #
#   # #    #  # # 
# ### # ## # ##
#     # ##    #  
#################

Input:
+-----------------+
|\                 \
+ \                 \
 \ \                 \
  \ \                 \
   \ \                 \
    \ \                 \
     \ \                 \
      \ \                 \
       \ +-----------------+
        \|                 | 
         +-----------------+

Output:
###
###
###

Input: (Note leading whitespace)
      +-----+     +-----+
      |\     \    |\     \
      + \     \   + \     \
   +-----+-----+-----+-----+
   |\     \    |\     \    | 
   + \     \---+ \     \---+  
    \ +-----+-----+-----+-----+
     \|     |\     \    |\     \
      +-----+ \     \---+ \     \
         +-----+-----+-----+-----+
         |\     \    |\     \    | 
         + \     \---+ \     \---+  
          \ +-----+   \ +-----+      
           \|     |    \|     |       
            +-----+     +-----+        

Output:
 # #
# #
 # #
# #

Hiatsu

Posted 2019-09-04T00:45:51.543

Reputation: 679

Can input/output be a list of strings? – Nick Kennedy – 2019-09-04T10:55:51.220

@Nick yes. That is what I meant by character matrix. – Hiatsu – 2019-09-04T11:37:40.737

great just wanted to clarify! – Nick Kennedy – 2019-09-04T11:38:07.150

1I really like this challenge! Just curious, why this way round and not producing the 3d maze? – AJFaraday – 2019-09-05T12:42:33.070

@AJFaraday Producing the maze (and more) has already been done in the challenge I linked. – Hiatsu – 2019-09-05T13:52:03.630

@Hiatsu Good point, well made. – AJFaraday – 2019-09-05T13:53:07.627

Answers

30

Python 2, 81 bytes

def f(M,k=1,r='',b=0):
 for c in M[k][k::6]:b^=c>' ';r+=' #'[b]
 print r;f(M,k+3)

Try it online!

Takes input as a list of strings (or a list of lists of characters). Prints the output, terminating with error.

The idea is similar to tsh's. We look at the characters marked as ? below to see which are spaces and which are \:

+-----------+
|?     ?     ?
+ \           \
 \ \     +-----+
  \ ?     ?    |?
   \ \     \---+
    \ +-----+
     \|?    |?
      +-----+

Within each row with ?'s, a \ marks a vertical ridge between a filled cell and an empty cell of the maze. Because these ridges are in top layer of the maze, their \ characters are never obscured by another maze element.

To look at the ? positions, the code iterates through rows k=1,4,7,... (zero-indexed), and in each row looks at every 6th position starting with position k. It tracks whether we're in an empty or full cell in the bit b, and flips that bit whenever a \ is encountered. After each character read, it appends the character for empty () or full (#) according to b, and prints the resulting string after the row is complete.

xnor

Posted 2019-09-04T00:45:51.543

Reputation: 115 687

That. Is. IMPRESSIVE. – connectyourcharger – 2019-09-04T22:41:00.597

19

JavaScript (Node.js), 85 bytes

a=>a.flatMap(u=(l,y)=>y%3?[]:[l.flatMap((c,x)=>x<y|(x-=y+3)%6?[]:' #'[u[x]^=c+1<0])])

Try it online!

Basic idea is: we only care about the characters on \$ (6x+3y+3,3y) \$. If it is a dash (-), current cell has the different value with the one on its top, and if it is a space (), current cell has the same value.

Thanks @Arnauld, saved 7 bytes

tsh

Posted 2019-09-04T00:45:51.543

Reputation: 13 072

very nice insight – Jonah – 2019-09-04T04:47:05.760

5

Jelly, 22 20 bytes

ṫ"J‘$m3n⁶m€6Ż^\ị⁾# Ḋ

Try it online!

A monadic link taking a Jelly string as input and returning the processed maze as a Jelly string including one row of trailing whitespace.

1 byte could be saved if a single line of leading whitespace were acceptable.

Took some inspiration from @tsh’s formula, so be sure to upvote that one too!

Explanation

ṫ"  $                | Tail each string using a paired member of the following:
  J                  | - Sequence along the list of strings
   ‘                 | - Incremented by 1
     m3              | Take every 3rd string (1st, 4th, 7th, ...)
       n⁶            | Not equal to space character
         m€6         | Within each list take every 6th item (1st, 7th, ...)
            Ż        | Prepend a zero to the list
             ^\      | Reduce using xor, collecting up results; vectorised across lists (so starts with 0 xor first list, then output of that xor second list, and so on)
               ị⁾#   | Index into "#", " "
                   Ḋ | Remove first list

Nick Kennedy

Posted 2019-09-04T00:45:51.543

Reputation: 11 829

5

05AB1E, 25 22 bytes

-1 byte thanks to Kevin Cruijssen

εN3%iN.$6ιнηðÊO„ #sèJ,

Try it online!

Port of xnor's Python answer. Takes input as a character matrix. The TIO link shows input as a multiline string for readability, with the |€S header converting that to the character matrix format.

Grimmy

Posted 2019-09-04T00:45:51.543

Reputation: 12 521

124 bytes: ε'\¢„ #sè} to ðм€g„ #sè – Kevin Cruijssen – 2019-09-10T08:22:27.557

Wow, nice find! See the answer for further improvements. PS: I am confused about the difference between м and K. – Grimmy – 2019-09-10T11:05:08.547

3

Retina 0.8.2, 72 bytes

¶(?<=(.|(¶))+)(?<-2>.)+
¶
-4G`
.+¶(.+)¶.+
$1
T` `#`\\  +\\
.(.)....|.
$1

Try it online! Explanation:

¶(?<=(.|(¶))+)(?<-2>.)+
¶

De-skew all of the lines.

-4G`

Delete the last three lines as I don't need them.

.+¶(.+)¶.+
$1

Keep only the middle of each group of three lines. (In Retina 1, I believe the above two stages can be done in a single stage: ,G1,3,-5`.)

T` `#`\\  +\\

Fill in the faces of the blocks.

.(.)....|.
$1

Keep only the second character of each block.

Neil

Posted 2019-09-04T00:45:51.543

Reputation: 95 035

2

C (clang), 120 117 bytes

o,c,t,s,r;f(char*m){for(s=o=0;*m;!r?t^=*m!=32,s=t?35:46:0)*++m==10?m-=~++o,c=t=0,s=10:0,r||printf(&s),r=c++%6|o%3-1;}

Try it online!

Inspired by the others answers.

'\'=92   ' '=32=>46='.'  '#'=35   '\n'=10 
// o offset == // l line 
// c line counter 
// t toggle 
// r => ? test, point to inspect 
for(o=s=0;*m;
!r?t=*m-32?!t:t,s=t?35:46:0) // t^=*m!=32 @ceilingcat 
// if test(r) is enabled: toggle(t) and sets (s)

*++m==10?m-=~++o,c=t=0,s=10:0,
// next char => if it's \n overwrites (s)
// and increments offset(o) and move pointer(m)

r || printf (&s)
// r or print! Thanks to @ceilingcat
// instead of 
    *++m-10?0:(m-=~++o,c=t=0,s=10),
    !r*s?putchar(s):0, 
 Saved 5 !

r=c++%6|o%3-1;// enable test every 6 x 3+1 positions

AZTECCO

Posted 2019-09-04T00:45:51.543

Reputation: 2 441