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 code-golf, shortest wins!
Testcases
,円 3 =>
\
\
\
---, 3 =>
---------
|
|
|, 3 =>
|
|
|
|
|
|
|
|
|
|\_/|
| |
\_/ , 3 =>
| \ / |
| \ / |
| \___/ |
| |
| |
| |
\ /
\ /
\___/
_____
\ /
/ \
\___/, 3 =>
_______________
\ /
\ /
\ /
/ \
/ \
/ \
\ /
\ /
\_________/
/\
/ \
/____\
||
||
_/__\_, 3 =>
/\
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ ____________ \
| |
| |
| |
| |
| |
| |
/ \
/ \
___/ ______ \___
\/
\/, 5 =>
\ /
\ /
\ /
\ /
\/
\ /
\ /
\ /
\ /
\/
/-/
\-,円 7 =>
/ /
/ /
/ /
/ ------- /
/ /
/ /
/ /
\ \
\ \
\ \
\ ------- \
\ \
\ \
\ \
_ _
/ \_/ \
| | | |
|_| |_|, 11 =>
___________ ___________
/ \ / \
/ \ / \
/ \ / \
/ \ / \
/ \ / \
/ \ / \
/ \ / \
/ \ / \
/ \ / \
/ \ / \
/ \___________/ \
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| ___________ | | ___________ |
__ __ __ __ ___
/\ /\ | |\ | | / | | /\ | |
/ \/ \ | | \ | |-- | |--\ /__\ |-- |
/ \ | | \| |__ \__ | \ / \ | | , 5 =>
__________ __________ __________ __________ _______________
/\ /\ | | \ | | / | | /\ | |
/ \ / \ | | \ | | / | | / \ | |
/ \ / \ | | \ | | / | | / \ | |
/ \ / \ | | \ | | / | | / \ | |
/ \ / \ | | \ | | / | | / \ | |
/ \ / \ | | \ | | | | \ / \ | |
/ \ / \ | | \ | | | | \ / \ | |
/ \ / \ | | \ | | ---------- | | ---------- \ / \ | ---------- |
/ \ / \ | | \ | | | | \ / \ | |
/ \/ \ | | \ | | | | \ / __________ \ | |
/ \ | | \ | | \ | \ / \ | |
/ \ | | \ | | \ | \ / \ | |
/ \ | | \ | | \ | \ / \ | |
/ \ | | \ | | \ | \ / \ | |
/ \ | | \ | | __________ \__________ | \ / \ | |
-
\$\begingroup\$ Can you take input as a matrix of characters? \$\endgroup\$Jonah– Jonah2021年07月30日 15:23:08 +00:00Commented Jul 30, 2021 at 15:23
-
\$\begingroup\$ @Jonah yes. Adding \$\endgroup\$emanresu A– emanresu A2021年07月30日 20:43:48 +00:00Commented Jul 30, 2021 at 20:43
-
\$\begingroup\$ Related. \$\endgroup\$jimmy23013– jimmy230132021年08月13日 15:30:14 +00:00Commented Aug 13, 2021 at 15:30
11 Answers 11
APL(Dyalog Unicode), (削除) 118 114 90 88 83 (削除ここまで) 80 bytes SBCS
{⊃,/⍪⌿⍵{' '⍺[⍵]} ̈1+(⍺ ⍺∘⍴ ̈o(⌽o←∘.=⍨⍳⍺)i(⌽⍺/⍺↑1)(⍉⍺ ⍺⍴i←(⌈⍺÷2)=⍳⍺)0)['\/|_- '⍳⍵]}
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.
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
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.
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];}
- 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.
-
\$\begingroup\$ 135 bytes \$\endgroup\$ceilingcat– ceilingcat2025年07月20日 20:07:44 +00:00Commented Jul 20 at 20:07
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}
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.
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)
-
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\$dingledooper– dingledooper2021年08月02日 18:24:17 +00:00Commented 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– ovs2021年08月02日 20:49:58 +00:00Commented 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\$dingledooper– dingledooper2021年08月02日 21:59:02 +00:00Commented Aug 2, 2021 at 21:59
Charcoal, 55 bytes
Nθ≔⊘⊕θη↑WS«J0+θjFι¿=κ_×ばつθκ«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«J0+θ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.
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`
`
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`
`
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`
`
-
1\$\begingroup\$ 151 I think \$\endgroup\$emanresu A– emanresu A2021年08月05日 05:35:49 +00:00Commented Aug 5, 2021 at 5:35
-
\$\begingroup\$ @emanresuA Nice, managed to take it several bytes even lower! \$\endgroup\$darrylyeo– darrylyeo2021年08月07日 22:34:54 +00:00Commented Aug 7, 2021 at 22:34
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]}})}}
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
}
})
}
}