23
\$\begingroup\$

Related

Given a piece of ascii art and a factor to enlarge it by, which will always be an odd number >1, replace each character with the corresponding ascii-art, resized to fit on a grid the size of the input number:

Character What to do
\
\  
\
\
A line of \ to the length of the enlarging factor, padded to form a line.
/
  /
/
/
A line of / to the length of the enlarging factor, padded to form a line.
|
 | 
|
|
A line of | to the length of the enlarging factor, centred horizontally.
-
   
---
A line of - to the length of the enlarging factor, centered vertically.
_
   

___
A line of _ to the length of the enlarging factor, at the bottom of the square it's in.

And of course, a space should be resized to a n-by-n grid of spaces. The input will only contain these six characters, plus newlines.

You may take input as a list of lines, a matrix of characters, whatever.

This is a bit confusing, so here's an example:

-\
 /, 3 =>
   \  
--- \ 
     \
     /
    / 
   /  

Because each character is enlarged to size 3.

Any trailing whitespace is allowed.

Scoring

This is , shortest wins!

Testcases

\, 3 =>
\
 \
  \

---, 3 =>
         
---------
         

|
|
|, 3 =>
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 

|\_/|
|   |
 \_/ , 3 =>
 | \       / | 
 |  \     /  | 
 |   \___/   | 
 |           | 
 |           | 
 |           | 
   \       /   
    \     /    
     \___/     

_____
\   /
/   \
\___/, 3 => 
               
               
_______________
\             /
 \           / 
  \         /  
  /         \  
 /           \ 
/             \
\             /
 \           / 
  \_________/  

  /\  
 /  \ 
/____\
  ||  
  ||  
_/__\_, 3 => 
        /\        
       /  \       
      /    \      
     /      \     
    /        \    
   /          \   
  /            \  
 /              \ 
/  ____________  \
       |  |       
       |  |       
       |  |       
       |  |       
       |  |       
       |  |       
     /      \     
    /        \    
___/  ______  \___

\/
\/, 5 =>
\        /
 \      / 
  \    /  
   \  /   
    \/    
\        /
 \      / 
  \    /  
   \  /   
    \/    

/-/
\-\, 7 => 
      /             /
     /             / 
    /             /  
   /   -------   /   
  /             /    
 /             /     
/             /      
\             \      
 \             \     
  \             \    
   \   -------   \   
    \             \  
     \             \ 
      \             \

 _   _ 
/ \_/ \
| | | |
|_| |_|, 11 => 
                                                                             
                                                                             
                                                                             
                                                                             
                                                                             
                                                                             
                                                                             
                                                                             
                                                                             
                                                                             
           ___________                                 ___________           
          /           \                               /           \          
         /             \                             /             \         
        /               \                           /               \        
       /                 \                         /                 \       
      /                   \                       /                   \      
     /                     \                     /                     \     
    /                       \                   /                       \    
   /                         \                 /                         \   
  /                           \               /                           \  
 /                             \             /                             \ 
/                               \___________/                               \
     |                     |                     |                     |     
     |                     |                     |                     |     
     |                     |                     |                     |     
     |                     |                     |                     |     
     |                     |                     |                     |     
     |                     |                     |                     |     
     |                     |                     |                     |     
     |                     |                     |                     |     
     |                     |                     |                     |     
     |                     |                     |                     |     
     |                     |                     |                     |     
     |                     |                     |                     |     
     |                     |                     |                     |     
     |                     |                     |                     |     
     |                     |                     |                     |     
     |                     |                     |                     |     
     |                     |                     |                     |     
     |                     |                     |                     |     
     |                     |                     |                     |     
     |                     |                     |                     |     
     |                     |                     |                     |     
     |     ___________     |                     |     ___________     |     

                       __    __   __             __  ___
  /\  /\    |  |\  |  |     /    |  |     /\    |     | 
 /  \/  \   |  | \ |  |--  |     |--\    /__\   |--   | 
/        \  |  |  \|  |__   \__  |   \  /    \  |     | , 5 =>
                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                        
                                                                                                                   __________                    __________               __________                                                                 __________          _______________
              /\                  /\                          |              |  \                |              |                               /                      |              |                               /\                          |                             |       
             /  \                /  \                         |              |   \               |              |                              /                       |              |                              /  \                         |                             |       
            /    \              /    \                        |              |    \              |              |                             /                        |              |                             /    \                        |                             |       
           /      \            /      \                       |              |     \             |              |                            /                         |              |                            /      \                       |                             |       
          /        \          /        \                      |              |      \            |              |                           /                          |              |                           /        \                      |                             |       
         /          \        /          \                     |              |       \           |              |                        |                             |            \                            /          \                     |                             |       
        /            \      /            \                    |              |        \          |              |                        |                             |             \                          /            \                    |                             |       
       /              \    /              \                   |              |         \         |              |  ----------            |                             |  ----------  \                        /              \                   |  ----------                 |       
      /                \  /                \                  |              |          \        |              |                        |                             |               \                      /                \                  |                             |       
     /                  \/                  \                 |              |           \       |              |                        |                             |                \                    /    __________    \                 |                             |       
    /                                        \                |              |            \      |              |                           \                          |                 \                  /                    \                |                             |       
   /                                          \               |              |             \     |              |                            \                         |                  \                /                      \               |                             |       
  /                                            \              |              |              \    |              |                             \                        |                   \              /                        \              |                             |       
 /                                              \             |              |               \   |              |                              \                       |                    \            /                          \             |                             |       
/                                                \            |              |                \  |              |  __________                   \__________            |                     \          /                            \            |                             |       

Reference implementation

\$\endgroup\$
3
  • \$\begingroup\$ Can you take input as a matrix of characters? \$\endgroup\$
    – Jonah
    Commented Jul 30, 2021 at 15:23
  • \$\begingroup\$ @Jonah yes. Adding \$\endgroup\$
    – emanresu A
    Commented Jul 30, 2021 at 20:43
  • \$\begingroup\$ Related. \$\endgroup\$
    – jimmy23013
    Commented Aug 13, 2021 at 15:30

11 Answers 11

9
\$\begingroup\$

APL(Dyalog Unicode), 118 114 90 88 83 80 bytes SBCS

{⊃,/⍪⌿⍵{' '⍺[⍵]}¨1+(⍺ ⍺∘⍴¨o(⌽o←∘.=⍨⍳⍺)i(⌽⍺/⍺↑1)(⍉⍺ ⍺⍴i←(⌈⍺÷2)=⍳⍺)0)['\/|_- '⍳⍵]}

Try it on APLgolf!

A dfn submission which takes a char matrix on the right and a scale factor on the left.

Indexes each character into its specific pattern, and then uses the original matrix to index back into it.

More byte saves can be done by figuring out a formula for getting the boolean arrays.

\$\endgroup\$
8
+50
\$\begingroup\$

V (vim), 311 bytes

"aDj:%s:\([ \-_]\):=repeat("\\1",a)
:g
:%s:\\:\\=repeat(" ",a-1)
:g
:%s:/:=repeat(" ",a-1)
/:g
:%s:|:=repeat(" ",a/2)
|=repeat(" ",a/2)
:g
{qqYp:s:\\ : \\:ge
:s: /:/ :ge
qdkG{Go
ggqtjjkk@a@qdd@tq@tggqb@ajk:s:_:Y:ge
j@bq@bi=a/2+1
D@"kkqc:s:-:X:ge
@ak@cq@c:%s:[-_]: :g
:%s:X:-:g
:%s:Y:_:g
gg:s:-: :g

Try it online!

Thanks to PyGamer for the idea of solving this in Vim. It's not extremely well golfed, can change some substitutions and bad hacks around the many macros that are in use.

Outputs the required art with two trailing newlines.

\$\endgroup\$
8
\$\begingroup\$

C (clang), 170 147 143 137 bytes

a,j,i;f(*m,x,z){for(;*m;m+=x)for(j=z;j--;puts(""))for(i=-1;++i<x*z;putchar((a-92?a-47?a-45?a-95|j:j-~j-z:i%z-j:~j+z-i%z)?32:a))a=m[i/z];}

Try it online!

  • thanks to @ceilingcat suggestion !
  • added for loop instead of recursion
  • thanks to @Johan du Toit for suggesting using int*array as input!

f(*m,x,z){ function taking:

  • m : char int array without newlines
  • x : width
  • z : scale

m+=x;*m&&f(m,x,z); => for(;*m;m+=x)
for every row of input, loop actually better than recursion.

for(j=z;j--;puts(""))
we iterate z times every row of input and put \n each time.

for(i=-1;++i<x*z;putchar(..) )
we put x*z characters.

a=m[i/z]
we use a to save on m[i/z] repetitions which is current input being enlarged.

putchar(( ... )?32:a
... => many nested ternary operators to select proper character based on a and i / j relations which evaluates to 1 or 0 , we then puts a space or a.

\$\endgroup\$
0
6
\$\begingroup\$

J, 89 bytes

[(a{~[:,/[:,./"3[*({0:0}(,:|.)@=@i.,/@,~(1,>.@-:)(,:~|:)@|."{1:0},~$0:))~(a=.' _|-\/')i.]

Try it online!

\$\endgroup\$
6
+200
\$\begingroup\$

K (oK), 261 184 165 163 159 bytes

{k:y;v:" ";a:{[g]{(x#v),g,(k-x+1)#v}'!k};h:{[s]{k#s@x=_k%2}'!k};,/{,/'+{$[92=x;a x;47=x;|:'a x;45=x;h v,x;95=x;{k#" _"@x=k-1}'!k;v=x;(k;k)#v;+h v,x]}'x}'";"\x}

Try it online!

I lost my sanity several times while creating this. Thanks to ngn and Razetime for helping me with this.

Thanks to Razetime for helping me to golf off a lot.

The basic approach is to split by newlines, replace each character with a list of subrows, take the transpose of that, join each line, and flatten.

\$\endgroup\$
6
\$\begingroup\$

K (ngn/k), 51 bytes

{,/,'/'`c$32|x*(a@<a;+a;|=y;=y;a=:|a:y#'!y)8!19!-x}

Try it online!

\$\endgroup\$
3
\$\begingroup\$

Python 2, 135 bytes

Takes input as a list of lines.

s,f=input()
R=range(f)
for r in s:
 for w in R:print''.join([i-w,i-~w-f,w-f/2,f+~w,i-f/2][ord(c)%23%5]and' 'or c for c in r for i in R)

Try it online!

\$\endgroup\$
3
  • 1
    \$\begingroup\$ This is a neat answer. Although unless I'm reading wrong, the task requires you to also input an enlarge factor (it's not assumed to be 3). \$\endgroup\$ Commented Aug 2, 2021 at 18:24
  • \$\begingroup\$ @dingledooper Thank you for telling me, I should really spend a bit more time reading the challenges. Now fixed for a couple of bytes (And no big numbers involved anymore :/). \$\endgroup\$
    – ovs
    Commented Aug 2, 2021 at 20:49
  • \$\begingroup\$ The thing is, I had also made this exact same mistake when I tried the challenge a few days ago, only to realize it as I was ready to submit. Not just you :P. \$\endgroup\$ Commented Aug 2, 2021 at 21:59
2
\$\begingroup\$

Charcoal, 55 bytes

Nθ≔⊘⊕θη↑WS«J⁰⁺θⅉFι¿⁼κ_×θκ«M⊖η↗≡κ-P-η/P/η|P|η\P\ηPκM⊖η↘→

Try it online! Link is to verbose version of code. Explanation:

Nθ≔⊘⊕θη

Input the scale factor n and calculate half, rounded up.

↑WS«J⁰⁺θⅉ

Output each transformed row on its own set of n lines.

Fι

Loop through the characters on each line.

¿⁼κ_×θκ«

If the next character is a _ then print n of them, otherwise...

M⊖η↗

Move to the centre of the square.

≡κ-P-η/P/η|P|η\P\ηPκ

Print a line in the desired direction. (TIO's version of Charcoal doesn't support computed multidirectionals, so I'm not sure whether that would beat a switch statement.)

M⊖η↘→

Move to the bottom left of the next square.

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

JavaScript (ES2020), 157 151 148 147 bytes

Takes a 2D character array A and a size n as f(A)(n).

A=>n=>A.flatMap(L=>(N=[...Array(n)]).map((_,y)=>L.flatMap(c=>N.map((_,x)=>[a=y-n+1,a+y,a+=x,a+x-y]['_-/|'.indexOf(c)]??x-y?' ':c)).join``)).join`
`

Try it online!


JavaScript (ES2020), 157 151 148 147 bytes

A=>n=>A.flatMap(L=>(N=[...Array(n)]).map((_,y)=>L.flatMap(c=>N.map((_,x)=>({_:a=y-n+1,'-':a+y,'/':a+=x,'|':a+x-y})[c]??x-y?' ':c)).join``)).join`
`

Try it online!


JavaScript (ES2019), 161 158 152 149 148 bytes

A=>n=>A.flatMap(L=>(N=[...Array(n)]).map((_,y)=>L.flatMap(c=>N.map((_,x)=>[a=y-n+1,x-y,a+y,a+=x,a+x-y]['_\\-/|'.indexOf(c)]?' ':c)).join``)).join`
`

Try it online!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ 151 I think \$\endgroup\$
    – emanresu A
    Commented Aug 5, 2021 at 5:35
  • \$\begingroup\$ @emanresuA Nice, managed to take it several bytes even lower! \$\endgroup\$
    – darrylyeo
    Commented Aug 7, 2021 at 22:34
2
\$\begingroup\$

Haskell, 97 bytes

n%a|z<-[1-n,3-n..n]=[do c<-r;x<-z;max" "[c|(l,0)<-zip"|_/\\-"[x,y-n+1,y+x,y-x,y],c==l]|r<-a,y<-z]

Try it online!

I/O: size%listOfLines is a new list of lines.

\$\endgroup\$
1
\$\begingroup\$

PowerShell, 162 152 149 143 138 bytes

param($k,$o)$o|%{$l=$_;1..$k|%{$y=$_
-join($l|% t*y|%{$c=$_;1..$k|%{" $c"[@{1=$y-$_+$k+1
8=$_+$y
7=2*$_
6=2*$y
4=$y+1}[$c%13]-eq$k+1]}})}}

Try it online!

Less golfed:

param($k,$origLines)
$origLines|%{                           $line = $_
    1..$k|%{                            $y = $_
        -join($line|% toCharArray|%{    $char = $_
            1..$k|%{                    $x = $_
                $rasterFont = @{
                    1 = $y-$x+$k+1                      # \
                    8 = $x+$y                           # /
                    7 = 2*$x                            # |
                    6 = 2*$y                            # -
                    4 = $y+1                            # _
                }
                " $char"[$rasterFont[$char%13]-eq$k+1]  # space or $char
            }
        })
    }
}
\$\endgroup\$

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.