10
\$\begingroup\$

Your task here is to take a LifeOnTheEdge pattern and convert it to LifeOnTheSlope.

A LifeOnTheEdge pattern is composed of these four characters: |_L . A pattern corresponds to a certain arrangement of "on" edges in a square grid. The pattern is placed in the grid first with the characters in the cells, and each of the four letters specifies the state of the edges on the left and the bottom of that cell. | means the edge on the left is on, _ means the bottom edge is on, L means both of them are on and means neither of them are on.

For example the following LifeOnTheEdge:

|_L
 |

translates to:

. . . . .
|   |
. ._._. .
  |
. . . . .

Your task is however convert it to LifeOnTheSlope. LifeOnTheSlope is a LifeOnTheEdge equivalent but only uses three symbols: /\ . You should rotate the pattern 45-degree clockwise, for example the above example translates to:

/

/\/
  \

This is , so shortest answer wins.

EDIT: You can have leading and/or trailing spaces/newlines as long as the output itself (somewhere on the screen) is correct.

Test Cases

Input:
|_L
 | 
Output:
 /   
     
 /\/ 
   \ 

Input:
 |
_L
L_|
L_|
L_|
L_|
 | 
 |
Output:
        / 
     /\/  
    /\ \  
   /\ \/  
  /\ \/   
  \ \/    
  /\/     
 /        

Input:
__ __ __ __   __ __   __
|  | | ||L_   |_ | || L_
L_ L_|_L|L_   L_|L_|L |

Output:
 /\                        
/  \                       
\                          
 \  /\                     
   /  \                    
   \  /                    
    \/  \                  
        /\                 
      \/ /                 
       \/ /\               
         /\ \              
         \ \               
          \                
                           
               /\          
              /  \         
              \ \          
               \/ /\       
                 /  \      
                 \  /      
                  \/ /     
                    /      
                    \  /\  
                      /\ \ 
                        \
```
\$\endgroup\$
4
  • 2
    \$\begingroup\$ This question didn't get much attention in the sandbox, so if the I/O format looks cumbersome to you or there's other issue or this is a dupe, sorry. \$\endgroup\$ Aug 24, 2020 at 14:23
  • 3
    \$\begingroup\$ Can we have leading and/or trailing spaces/newlines as long as the output itself (somewhere on the screen) is correct? Also, could you perhaps add a few more test cases (perhaps some bigger ones)? \$\endgroup\$ Aug 24, 2020 at 15:46
  • 2
    \$\begingroup\$ See my answer for some suggested test cases (cc @KevinCruijssen). \$\endgroup\$
    – Arnauld
    Aug 24, 2020 at 16:23
  • 2
    \$\begingroup\$ @KevinCruijssen Yes you can. Downvoters explain. \$\endgroup\$ Aug 25, 2020 at 3:22

3 Answers 3

5
\$\begingroup\$

JavaScript (ES6),  135 120  119 bytes

Saved 16 bytes thanks to @Shaggy!

Expects either an array of strings or a matrix of characters. Returns a matrix of characters.

a=>[...a,...a[0]].map((_,y,b)=>b.map((_,x)=>'\\/ '[(c=(a[~(x-=y+a.length)>>1]||0)[x+y-~y>>1])=='_|'[x&=1]|c=='L'?x:2]))

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ 120? \$\endgroup\$
    – Shaggy
    Aug 24, 2020 at 16:34
  • 1
    \$\begingroup\$ @Shaggy Nice! Thank you. \$\endgroup\$
    – Arnauld
    Aug 24, 2020 at 16:44
  • 1
    \$\begingroup\$ 119 by ditching i. \$\endgroup\$
    – Shaggy
    Aug 24, 2020 at 16:53
4
\$\begingroup\$

Charcoal, 27 bytes

WS«P↘⭆ι§ /№|Lκ↓P↘⭆ι§ \№_Lκ←

Try it online! Link is to verbose version of code. Takes input as a newline-terminated list. Explanation:

WS«

For each line in the list...

P↘⭆ι§ /№|Lκ

Diagonally print /s for |s and Ls otherwise print spaces.

Move to the next line.

P↘⭆ι§ \№_Lκ

Diagonally print \s for _s and Ls otherwise print spaces.

Move to the previous column.

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

C (gcc), 195 186 bytes

T,N,a,A,b,x,y,z;f(m,X,Y)char*m;{for(x=T=y=0;x<Y*3;x++,y++,T+=~Y)for(z=X-~Y,a=x,b=y;z--;T++,b--)A=a++/2-Y,N=m[A+b/2*X],putchar(z?(A|b)>=0&A<X&b<Y*2?T%2?N%19?32:92:(N-76)%48?32:47:32:10);}

Try it online!

  • Saved 11 thanks to @ceilingcat

Example size X=3, Y=2

00 10 20  (x,y) indexes
01 11 21  of LOnH 
      mapped to below 

-2 0|-2 0|-1-1|-1-1| 0-2|
-2 0|-1 0|-1 0| 0-1| 0-1|
-1 1|-1 0| 0 0| 0 0| 1-1|
-1 1| 0 1| 0 0| 1 0| 1 0|
 0 2| 0 1| 1 1| 1 0| 2 0|
 0 2| 1 2| 1 1| 2 1| 2 0|
 1 3| 1 2| 2 2| 2 1| 3 1|
 1 3| 2 3| 2 2| 3 2| 3 1|

We start with x=-Y,y=0
We decrement x / increment y every 2 on first column and we do the inverse on each row.

Then we mask taking only valid indexes.

    |    |    |    |    |
    |    |    |    |    |
    |    | 0 0|    |    |
    | 0 1| 0 0| 1 0|    |
    | 0 1| 1 1| 1 0| 2 0|
    |    | 1 1| 2 1| 2 0|
    |    |    | 2 1|    |
    |    |    |    |    |

Now we have doubled (x,y) pairs one for |,L and the second for _,L

\$\endgroup\$
0

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.