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
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 =>
/-/
\-\
-
2\$\begingroup\$ It would be interesting if you had to auto-detect the enlargement factor (choosing the maximum). \$\endgroup\$Adamátor– Adamátor2022年01月20日 00:22:30 +00:00Commented Jan 20, 2022 at 0:22
6 Answers 6
Jelly, 7 bytes
»/9ÐƤ+€
A monadic Link accepting a list of lines that yields a list of lines.
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ÐƤ
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!
-
1\$\begingroup\$ @Fmbalbuena Rickrolling jokes are mostly fine in chat, but bringing them over to main is just clutter. \$\endgroup\$2022年01月19日 21:41:08 +00:00Commented Jan 19, 2022 at 21:41
J, 20 bytes
{.@-.&' '@,;.3~2 2&$
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 {.
.
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);
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:
Nθ
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.