5
\$\begingroup\$

The inverse of this question.

Your challenge is to, given a piece of ASCII art generated by the above question and its enlargement factor, shrink it down to its original size.

The enlargement process

Or look at this

ASCII art within a limited character set can be enlarged to a certain (odd) size by replacing certain characters with larger versions of themselves, like so:

-\
 |
_/
, 3 =>

   \
--- \ 
     \
    |
    |
    |
     /
    /
___/

Because each character is enlarged to a 3x3 square.

Only those six characters (\/|-_ ) can be enlarged, and only those will be in your input. For a more detailed explanation, see the linked challenge.

I/O may be as a char matrix, ascii art, list of rows, etc.

Testcases



\
 \
  \
, 3 =>
\


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


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


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


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

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


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


      /             /
     /             / 
    /             /  
   /   -------   /   
  /             /    
 /             /     
/             /      
\             \      
 \             \     
  \             \    
   \   -------   \   
    \             \  
     \             \ 
      \             \, 7 => 
/-/
\-\
\$\endgroup\$
1
  • 1
    \$\begingroup\$ It would be interesting if you had to auto-detect the enlargement factor (choosing the maximum). \$\endgroup\$
    – xigoi
    Jan 20, 2022 at 0:22

6 Answers 6

4
\$\begingroup\$

Jelly, 7 bytes

»/⁹ÐƤ⁺€

A monadic Link accepting a list of lines that yields a list of lines.

Try it online!

How?

»/⁹ÐƤ⁺€ - Link: list of lists of characters, Lines; pixel size, N
   ÐƤ   - for non-overlapping infixes
  ⁹     - ...of length: chain's right argument, N
 /      - ...yield: reduce by:
        -             maximum (vectorises)
                      (Note: space is less than any other character used)
      € - for each:
     ⁺  -   repeat the last link - i.e. do Ṁ⁹ÐƤ
\$\endgroup\$
2
\$\begingroup\$

JavaScript (ES6), 106 bytes

x=>n=>x.replace(/.+\n.+\n.+/g,y=>[...(z=y.split`
`)[~-n/2]].map((w,i)=>i%3-1?"":w<"!"?z[n-1][i]:w).join``)

Now actually works!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ @Fmbalbuena Rickrolling jokes are mostly fine in chat, but bringing them over to main is just clutter. \$\endgroup\$ Jan 19, 2022 at 21:41
2
\$\begingroup\$

J, 20 bytes

{.@-.&' '@,;.3~2 2&$

Try it online!

With (y x,:h w) u;.3 a we can split a into tiles of size h w while sliding the window by y x. Because we don't want overlapping tiles, we can simply build a 2x2 matrix of the input, e.g. 3 3,:3 3. On these tiles u gets applied, which flattens , the tile into a list, removes any whitespace -.&' ' and then reduces the tile to the first remaining element {..

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

Charcoal, 25 bytes

NθWS⊞υ⭆⪪ιθ⌈κE⪪υθ⭆⌈ι⌈Eι§νμ

Try it online! Link is to verbose version of code. Takes the enlargement factor followed by a list of newline-terminated strings. Explanation:

Nθ

Input the enlargement factor.

WS⊞υ⭆⪪ιθ⌈κ

Input the strings, but split them into substrings of length equal to the enlargement factor and take the maximum character of each substring.

E⪪υθ⭆⌈ι⌈Eι§νμ

Split the list of strings into sublists of length equal to the enlargement factor, then transpose the sublists and take the maximum character of each, joined back into a string, and print each sublist's string on its own line.

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

JavaScript, 84 bytes

a=>n=>a.map((r,i)=>r.map((c,j)=>(d=b[i/n|0]||=[])[x=j/n|0]=d[x]?.trim()||c),b=[])&&b

f=
a=>n=>a.map((r,i)=>r.map((c,j)=>(d=b[i/n|0]||=[])[x=j/n|0]=d[x]?.trim()||c),b=[])&&b

str2mat = str => str.split('\n').map(r => [...r]);
mat2str = mat => mat.map(r => r.join('')).join('\n');
test = (s, n) => console.log(mat2str(f(str2mat(s.slice(1, -1)))(n)));

test(String.raw`
\
 \
  \
`, 3);

test(String.raw`
---------
`, 3);

test(String.raw`
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
 | 
`, 3);

test(String.raw`
 | \       / | 
 |  \     /  | 
 |   \___/   | 
 |           | 
 |           | 
 |           | 
   \       /   
    \     /    
     \___/     
`, 3);

test(String.raw`
_______________
\             /
 \           / 
  \         /  
  /         \  
 /           \ 
/             \
\             /
 \           / 
  \_________/  
`, 3);

test(String.raw`
        /\        
       /  \       
      /    \      
     /      \     
    /        \    
   /          \   
  /            \  
 /              \ 
/  ____________  \
       |  |       
       |  |       
       |  |       
       |  |       
       |  |       
       |  |       
     /      \     
    /        \    
___/  ______  \___
`, 3);

test(String.raw`
\        /
 \      / 
  \    /  
   \  /   
    \/    
\        /
 \      / 
  \    /  
   \  /   
    \/    
`, 5);

test(String.raw`
      /             /
     /             / 
    /             /  
   /   -------   /   
  /             /    
 /             /     
/             /      
\             \      
 \             \     
  \             \    
   \   -------   \   
    \             \  
     \             \ 
      \             \
`, 7);

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

Haskell, 56 bytes

f n|let g[]=[];g x=maximum(take n x):g(drop n x)=g.map g

Try it online!

\$\endgroup\$

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.