45
\$\begingroup\$

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:
 # #
# #
 # #
# #

\$\endgroup\$
6
  • \$\begingroup\$ Can input/output be a list of strings? \$\endgroup\$ Sep 4, 2019 at 10:55
  • \$\begingroup\$ @Nick yes. That is what I meant by character matrix. \$\endgroup\$
    – Hiatsu
    Sep 4, 2019 at 11:37
  • \$\begingroup\$ great just wanted to clarify! \$\endgroup\$ Sep 4, 2019 at 11:38
  • 1
    \$\begingroup\$ I really like this challenge! Just curious, why this way round and not producing the 3d maze? \$\endgroup\$
    – AJFaraday
    Sep 5, 2019 at 12:42
  • \$\begingroup\$ @AJFaraday Producing the maze (and more) has already been done in the challenge I linked. \$\endgroup\$
    – Hiatsu
    Sep 5, 2019 at 13:52

6 Answers 6

31
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ That. Is. IMPRESSIVE. \$\endgroup\$
    – moltarze
    Sep 4, 2019 at 22:41
19
\$\begingroup\$

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

\$\endgroup\$
1
  • \$\begingroup\$ very nice insight \$\endgroup\$
    – Jonah
    Sep 4, 2019 at 4:47
5
\$\begingroup\$

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
\$\endgroup\$
5
\$\begingroup\$

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.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ 24 bytes: ε'\¢„ #sè} to ðм€g„ #sè \$\endgroup\$ Sep 10, 2019 at 8:22
  • \$\begingroup\$ Wow, nice find! See the answer for further improvements. PS: I am confused about the difference between м and K. \$\endgroup\$
    – Grimmy
    Sep 10, 2019 at 11:05
3
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

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
\$\endgroup\$
0

Your Answer

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

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