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 => 
/-/
\-\
pxeger
25.2k4 gold badges59 silver badges146 bronze badges
asked Jan 19, 2022 at 20:00
\$\endgroup\$
1
  • 2
    \$\begingroup\$ It would be interesting if you had to auto-detect the enlargement factor (choosing the maximum). \$\endgroup\$ Commented Jan 20, 2022 at 0:22

6 Answers 6

4
\$\begingroup\$

Jelly, 7 bytes

»/9ÐƤ+€

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

Try it online!

How?

»/9ÐƤ+€ - Link: list of lists of characters, Lines; pixel size, N
 ÐƤ - for non-overlapping infixes
 9 - ...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 Ṁ9ÐƤ
answered Jan 19, 2022 at 20:40
\$\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!

answered Jan 19, 2022 at 20:11
\$\endgroup\$
1
  • 1
    \$\begingroup\$ @Fmbalbuena Rickrolling jokes are mostly fine in chat, but bringing them over to main is just clutter. \$\endgroup\$ Commented 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 {..

answered Jan 19, 2022 at 22:37
\$\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);

answered Jan 20, 2022 at 7:05
\$\endgroup\$
1
  • \$\begingroup\$ 82 \$\endgroup\$ Commented May 27, 2024 at 0:39
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!

answered Jan 20, 2022 at 14:14
\$\endgroup\$
1
\$\begingroup\$

Charcoal, (削除) 25 (削除ここまで) 24 bytes

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

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

Input the enlargement factor.

WS⊞υι

Input the strings.

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

Split the list of strings into sublists of length equal to the enlargement factor, split each element of each sublist into strings of the same length, then transpose and take the maximum of the concatenation of each square.

answered Jan 19, 2022 at 21:28
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.