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

asked Jul 30, 2021 at 9:40
\$\endgroup\$
3
  • \$\begingroup\$ Can you take input as a matrix of characters? \$\endgroup\$ Commented Jul 30, 2021 at 15:23
  • \$\begingroup\$ @Jonah yes. Adding \$\endgroup\$ Commented Jul 30, 2021 at 20:43
  • \$\begingroup\$ Related. \$\endgroup\$ 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.

answered Jul 30, 2021 at 10:13
\$\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.

answered Aug 2, 2021 at 6:31
\$\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.

answered Jul 31, 2021 at 16:28
\$\endgroup\$
1
  • \$\begingroup\$ 135 bytes \$\endgroup\$ Commented Jul 20 at 20:07
6
\$\begingroup\$

J, 89 bytes

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

Try it online!

answered Jul 31, 2021 at 5:24
\$\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.

answered Aug 2, 2021 at 9:55
\$\endgroup\$
6
\$\begingroup\$

K (ngn/k), 51 bytes

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

Try it online!

answered Aug 5, 2021 at 12:59
\$\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!

answered Aug 2, 2021 at 9:50
\$\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\$ 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«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.

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.

answered Aug 1, 2021 at 20:17
\$\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!

answered Aug 5, 2021 at 4:43
\$\endgroup\$
2
  • 1
    \$\begingroup\$ 151 I think \$\endgroup\$ Commented Aug 5, 2021 at 5:35
  • \$\begingroup\$ @emanresuA Nice, managed to take it several bytes even lower! \$\endgroup\$ 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.

answered Aug 13, 2021 at 14:13
\$\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
 }
 })
 }
}
answered Aug 14, 2021 at 15:13
\$\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.