Draw this diamond pattern
Clash Royale CLAN TAG#URR8PPP
up vote
12
down vote
favorite
The below pattern will form the basis of this challenge.
/
/
/
/
/
// /
/ //
/
/
/
/
/
Given an input width and height, each >=1
, output the above ASCII art pattern repeated that many times, joining (and overlapping) at the small diamonds.
For example, here is an input with width = 2
and height = 1
:
/ /
/ /
/ /
/ /
/ /
// // /
/ // //
/ /
/ /
/ /
/ /
/ /
Here is an input width = 3
and height = 2
:
/ / /
/ / /
/ / /
/ / /
/ / /
// // // /
/ // // //
/ / /
/ / /
/ / /
/ / /
/ / /
/ / /
/ / /
/ / /
// // // /
/ // // //
/ / /
/ / /
/ / /
/ / /
/ / /
Rules and I/O
- Input and output can be given by any convenient method.
- You can print it to STDOUT or return it as a function result.
- Either a full program or a function are acceptable.
- Any amount of extraneous whitespace is acceptable, so long as the characters line up appropriately.
Standard loopholes are forbidden.- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
code-golf ascii-art
add a comment |
up vote
12
down vote
favorite
The below pattern will form the basis of this challenge.
/
/
/
/
/
// /
/ //
/
/
/
/
/
Given an input width and height, each >=1
, output the above ASCII art pattern repeated that many times, joining (and overlapping) at the small diamonds.
For example, here is an input with width = 2
and height = 1
:
/ /
/ /
/ /
/ /
/ /
// // /
/ // //
/ /
/ /
/ /
/ /
/ /
Here is an input width = 3
and height = 2
:
/ / /
/ / /
/ / /
/ / /
/ / /
// // // /
/ // // //
/ / /
/ / /
/ / /
/ / /
/ / /
/ / /
/ / /
/ / /
// // // /
/ // // //
/ / /
/ / /
/ / /
/ / /
/ / /
Rules and I/O
- Input and output can be given by any convenient method.
- You can print it to STDOUT or return it as a function result.
- Either a full program or a function are acceptable.
- Any amount of extraneous whitespace is acceptable, so long as the characters line up appropriately.
Standard loopholes are forbidden.- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
code-golf ascii-art
Loosely related
– Luis Mendo
2 hours ago
add a comment |
up vote
12
down vote
favorite
up vote
12
down vote
favorite
The below pattern will form the basis of this challenge.
/
/
/
/
/
// /
/ //
/
/
/
/
/
Given an input width and height, each >=1
, output the above ASCII art pattern repeated that many times, joining (and overlapping) at the small diamonds.
For example, here is an input with width = 2
and height = 1
:
/ /
/ /
/ /
/ /
/ /
// // /
/ // //
/ /
/ /
/ /
/ /
/ /
Here is an input width = 3
and height = 2
:
/ / /
/ / /
/ / /
/ / /
/ / /
// // // /
/ // // //
/ / /
/ / /
/ / /
/ / /
/ / /
/ / /
/ / /
/ / /
// // // /
/ // // //
/ / /
/ / /
/ / /
/ / /
/ / /
Rules and I/O
- Input and output can be given by any convenient method.
- You can print it to STDOUT or return it as a function result.
- Either a full program or a function are acceptable.
- Any amount of extraneous whitespace is acceptable, so long as the characters line up appropriately.
Standard loopholes are forbidden.- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
code-golf ascii-art
The below pattern will form the basis of this challenge.
/
/
/
/
/
// /
/ //
/
/
/
/
/
Given an input width and height, each >=1
, output the above ASCII art pattern repeated that many times, joining (and overlapping) at the small diamonds.
For example, here is an input with width = 2
and height = 1
:
/ /
/ /
/ /
/ /
/ /
// // /
/ // //
/ /
/ /
/ /
/ /
/ /
Here is an input width = 3
and height = 2
:
/ / /
/ / /
/ / /
/ / /
/ / /
// // // /
/ // // //
/ / /
/ / /
/ / /
/ / /
/ / /
/ / /
/ / /
/ / /
// // // /
/ // // //
/ / /
/ / /
/ / /
/ / /
/ / /
Rules and I/O
- Input and output can be given by any convenient method.
- You can print it to STDOUT or return it as a function result.
- Either a full program or a function are acceptable.
- Any amount of extraneous whitespace is acceptable, so long as the characters line up appropriately.
Standard loopholes are forbidden.- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
code-golf ascii-art
code-golf ascii-art
asked 5 hours ago
AdmBorkBork
25.4k362223
25.4k362223
Loosely related
– Luis Mendo
2 hours ago
add a comment |
Loosely related
– Luis Mendo
2 hours ago
Loosely related
– Luis Mendo
2 hours ago
Loosely related
– Luis Mendo
2 hours ago
add a comment |
5 Answers
5
active
oldest
votes
up vote
4
down vote
Canvas, 26 25 24 21 bytes
4/╬/╬⁰r:⤢n⁸{╵×↔¹A×├m↶
Try it here!
Explanation:
4/ create a 4-long diagonal
╬ quad-palindromize it - big inner diamond
/╬ quad-palindromize "/" - small diamond
⁰r center the two added vertically
:⤢n overlap with its transpose
⁷{ for each input:
╵× repeat the canvas input+1 times horizontally
↔ reverse horizontally
¹ the input,
A× times 10,
├ plus 2
m mold the canvas to that width
↶ rotate the canvas anti-clockwise, setting up for the other input
add a comment |
up vote
4
down vote
JavaScript (ES8), 167 161 bytes
Takes input as (width)(height)
.
w=>h=>(g=h=>h?([x=4106,4016,x,31305,21504,17010][(x=--h%10)>5?11-x:x]+'').replace(/./g,c=>'/\'[c^x>5]||''.padEnd(c-1)).repeat(w+1).slice(8)+`
`+g(h):'')(h*10+2)
Try it online!
How?
We encode the upper half of the pattern with digits:
$0$ means
$1$ means/
$n=2$ to $7$ means $n-1$ spaces
This gives:
0 ···/····· --> [3 spaces] [/] [] [5 spaces] --> 4106
1 ···/····· --> [3 spaces] [] [/] [5 spaces] --> 4016
2 ···/····· --> [3 spaces] [/] [] [5 spaces] --> 4106
3 ··/······ --> [2 spaces] [/] [2 spaces] [] [4 spaces] --> 31305
4 ·/······· --> [1 space] [/] [4 spaces] [] [3 spaces] --> 21504
5 /······/ --> [/] [6 spaces] [] [/] [] --> 17010
For the lower half, we use the rows $5$ to $2$ (i.e. in reverse order) with /
and inverted.
add a comment |
up vote
1
down vote
Charcoal, 24 bytes
F⁴«↖⁶¶/¶⟲T»F⊖NCχ⁰F⊖NC⁰χ
Try it online! Link is to verbose version of code. Explanation:
F⁴«
Repeat for each side of the original pattern.
↖⁶¶/¶
Draw the long diagonal and two short lines of the small diamond.
⟲T»
Rotate the entire canvas and repeat.
F⊖NCχ⁰
Copy the required number of times horizontally.
F⊖NC⁰χ
Copy the required number of times vertically.
add a comment |
up vote
1
down vote
Haskell, 179 bytes
k '\'='/'
k '/'='\'
k x=x
f x=take(10*x+2)
w#h=map(f w.cycle).f h.drop 9.cycle$(++).reverse=<<map(map k)$["\/\ /"," \ / "," \ / "," \/ "," /\ "]
Try it online!
add a comment |
up vote
0
down vote
Perl 5 -p
, 148 bytes
$_='3A3'x$_.$/.'3B3
3A3
2/2\2
1/4\1
A6A
B6B
1\4/1
2\2/2
3B3
3A3
'=~s/^.*$/$&x$_/mger x<>.'3B3'x$_;s|A+|/\|g;s|B+|\/|g;s/d/$"x$&/ge;s|^ | |gm
Try it online!
add a comment |
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
Canvas, 26 25 24 21 bytes
4/╬/╬⁰r:⤢n⁸{╵×↔¹A×├m↶
Try it here!
Explanation:
4/ create a 4-long diagonal
╬ quad-palindromize it - big inner diamond
/╬ quad-palindromize "/" - small diamond
⁰r center the two added vertically
:⤢n overlap with its transpose
⁷{ for each input:
╵× repeat the canvas input+1 times horizontally
↔ reverse horizontally
¹ the input,
A× times 10,
├ plus 2
m mold the canvas to that width
↶ rotate the canvas anti-clockwise, setting up for the other input
add a comment |
up vote
4
down vote
Canvas, 26 25 24 21 bytes
4/╬/╬⁰r:⤢n⁸{╵×↔¹A×├m↶
Try it here!
Explanation:
4/ create a 4-long diagonal
╬ quad-palindromize it - big inner diamond
/╬ quad-palindromize "/" - small diamond
⁰r center the two added vertically
:⤢n overlap with its transpose
⁷{ for each input:
╵× repeat the canvas input+1 times horizontally
↔ reverse horizontally
¹ the input,
A× times 10,
├ plus 2
m mold the canvas to that width
↶ rotate the canvas anti-clockwise, setting up for the other input
add a comment |
up vote
4
down vote
up vote
4
down vote
Canvas, 26 25 24 21 bytes
4/╬/╬⁰r:⤢n⁸{╵×↔¹A×├m↶
Try it here!
Explanation:
4/ create a 4-long diagonal
╬ quad-palindromize it - big inner diamond
/╬ quad-palindromize "/" - small diamond
⁰r center the two added vertically
:⤢n overlap with its transpose
⁷{ for each input:
╵× repeat the canvas input+1 times horizontally
↔ reverse horizontally
¹ the input,
A× times 10,
├ plus 2
m mold the canvas to that width
↶ rotate the canvas anti-clockwise, setting up for the other input
Canvas, 26 25 24 21 bytes
4/╬/╬⁰r:⤢n⁸{╵×↔¹A×├m↶
Try it here!
Explanation:
4/ create a 4-long diagonal
╬ quad-palindromize it - big inner diamond
/╬ quad-palindromize "/" - small diamond
⁰r center the two added vertically
:⤢n overlap with its transpose
⁷{ for each input:
╵× repeat the canvas input+1 times horizontally
↔ reverse horizontally
¹ the input,
A× times 10,
├ plus 2
m mold the canvas to that width
↶ rotate the canvas anti-clockwise, setting up for the other input
edited 4 hours ago
answered 5 hours ago
dzaima
13.8k21653
13.8k21653
add a comment |
add a comment |
up vote
4
down vote
JavaScript (ES8), 167 161 bytes
Takes input as (width)(height)
.
w=>h=>(g=h=>h?([x=4106,4016,x,31305,21504,17010][(x=--h%10)>5?11-x:x]+'').replace(/./g,c=>'/\'[c^x>5]||''.padEnd(c-1)).repeat(w+1).slice(8)+`
`+g(h):'')(h*10+2)
Try it online!
How?
We encode the upper half of the pattern with digits:
$0$ means
$1$ means/
$n=2$ to $7$ means $n-1$ spaces
This gives:
0 ···/····· --> [3 spaces] [/] [] [5 spaces] --> 4106
1 ···/····· --> [3 spaces] [] [/] [5 spaces] --> 4016
2 ···/····· --> [3 spaces] [/] [] [5 spaces] --> 4106
3 ··/······ --> [2 spaces] [/] [2 spaces] [] [4 spaces] --> 31305
4 ·/······· --> [1 space] [/] [4 spaces] [] [3 spaces] --> 21504
5 /······/ --> [/] [6 spaces] [] [/] [] --> 17010
For the lower half, we use the rows $5$ to $2$ (i.e. in reverse order) with /
and inverted.
add a comment |
up vote
4
down vote
JavaScript (ES8), 167 161 bytes
Takes input as (width)(height)
.
w=>h=>(g=h=>h?([x=4106,4016,x,31305,21504,17010][(x=--h%10)>5?11-x:x]+'').replace(/./g,c=>'/\'[c^x>5]||''.padEnd(c-1)).repeat(w+1).slice(8)+`
`+g(h):'')(h*10+2)
Try it online!
How?
We encode the upper half of the pattern with digits:
$0$ means
$1$ means/
$n=2$ to $7$ means $n-1$ spaces
This gives:
0 ···/····· --> [3 spaces] [/] [] [5 spaces] --> 4106
1 ···/····· --> [3 spaces] [] [/] [5 spaces] --> 4016
2 ···/····· --> [3 spaces] [/] [] [5 spaces] --> 4106
3 ··/······ --> [2 spaces] [/] [2 spaces] [] [4 spaces] --> 31305
4 ·/······· --> [1 space] [/] [4 spaces] [] [3 spaces] --> 21504
5 /······/ --> [/] [6 spaces] [] [/] [] --> 17010
For the lower half, we use the rows $5$ to $2$ (i.e. in reverse order) with /
and inverted.
add a comment |
up vote
4
down vote
up vote
4
down vote
JavaScript (ES8), 167 161 bytes
Takes input as (width)(height)
.
w=>h=>(g=h=>h?([x=4106,4016,x,31305,21504,17010][(x=--h%10)>5?11-x:x]+'').replace(/./g,c=>'/\'[c^x>5]||''.padEnd(c-1)).repeat(w+1).slice(8)+`
`+g(h):'')(h*10+2)
Try it online!
How?
We encode the upper half of the pattern with digits:
$0$ means
$1$ means/
$n=2$ to $7$ means $n-1$ spaces
This gives:
0 ···/····· --> [3 spaces] [/] [] [5 spaces] --> 4106
1 ···/····· --> [3 spaces] [] [/] [5 spaces] --> 4016
2 ···/····· --> [3 spaces] [/] [] [5 spaces] --> 4106
3 ··/······ --> [2 spaces] [/] [2 spaces] [] [4 spaces] --> 31305
4 ·/······· --> [1 space] [/] [4 spaces] [] [3 spaces] --> 21504
5 /······/ --> [/] [6 spaces] [] [/] [] --> 17010
For the lower half, we use the rows $5$ to $2$ (i.e. in reverse order) with /
and inverted.
JavaScript (ES8), 167 161 bytes
Takes input as (width)(height)
.
w=>h=>(g=h=>h?([x=4106,4016,x,31305,21504,17010][(x=--h%10)>5?11-x:x]+'').replace(/./g,c=>'/\'[c^x>5]||''.padEnd(c-1)).repeat(w+1).slice(8)+`
`+g(h):'')(h*10+2)
Try it online!
How?
We encode the upper half of the pattern with digits:
$0$ means
$1$ means/
$n=2$ to $7$ means $n-1$ spaces
This gives:
0 ···/····· --> [3 spaces] [/] [] [5 spaces] --> 4106
1 ···/····· --> [3 spaces] [] [/] [5 spaces] --> 4016
2 ···/····· --> [3 spaces] [/] [] [5 spaces] --> 4106
3 ··/······ --> [2 spaces] [/] [2 spaces] [] [4 spaces] --> 31305
4 ·/······· --> [1 space] [/] [4 spaces] [] [3 spaces] --> 21504
5 /······/ --> [/] [6 spaces] [] [/] [] --> 17010
For the lower half, we use the rows $5$ to $2$ (i.e. in reverse order) with /
and inverted.
edited 2 hours ago
answered 5 hours ago
Arnauld
68k584288
68k584288
add a comment |
add a comment |
up vote
1
down vote
Charcoal, 24 bytes
F⁴«↖⁶¶/¶⟲T»F⊖NCχ⁰F⊖NC⁰χ
Try it online! Link is to verbose version of code. Explanation:
F⁴«
Repeat for each side of the original pattern.
↖⁶¶/¶
Draw the long diagonal and two short lines of the small diamond.
⟲T»
Rotate the entire canvas and repeat.
F⊖NCχ⁰
Copy the required number of times horizontally.
F⊖NC⁰χ
Copy the required number of times vertically.
add a comment |
up vote
1
down vote
Charcoal, 24 bytes
F⁴«↖⁶¶/¶⟲T»F⊖NCχ⁰F⊖NC⁰χ
Try it online! Link is to verbose version of code. Explanation:
F⁴«
Repeat for each side of the original pattern.
↖⁶¶/¶
Draw the long diagonal and two short lines of the small diamond.
⟲T»
Rotate the entire canvas and repeat.
F⊖NCχ⁰
Copy the required number of times horizontally.
F⊖NC⁰χ
Copy the required number of times vertically.
add a comment |
up vote
1
down vote
up vote
1
down vote
Charcoal, 24 bytes
F⁴«↖⁶¶/¶⟲T»F⊖NCχ⁰F⊖NC⁰χ
Try it online! Link is to verbose version of code. Explanation:
F⁴«
Repeat for each side of the original pattern.
↖⁶¶/¶
Draw the long diagonal and two short lines of the small diamond.
⟲T»
Rotate the entire canvas and repeat.
F⊖NCχ⁰
Copy the required number of times horizontally.
F⊖NC⁰χ
Copy the required number of times vertically.
Charcoal, 24 bytes
F⁴«↖⁶¶/¶⟲T»F⊖NCχ⁰F⊖NC⁰χ
Try it online! Link is to verbose version of code. Explanation:
F⁴«
Repeat for each side of the original pattern.
↖⁶¶/¶
Draw the long diagonal and two short lines of the small diamond.
⟲T»
Rotate the entire canvas and repeat.
F⊖NCχ⁰
Copy the required number of times horizontally.
F⊖NC⁰χ
Copy the required number of times vertically.
answered 4 hours ago
Neil
77.4k744174
77.4k744174
add a comment |
add a comment |
up vote
1
down vote
Haskell, 179 bytes
k '\'='/'
k '/'='\'
k x=x
f x=take(10*x+2)
w#h=map(f w.cycle).f h.drop 9.cycle$(++).reverse=<<map(map k)$["\/\ /"," \ / "," \ / "," \/ "," /\ "]
Try it online!
add a comment |
up vote
1
down vote
Haskell, 179 bytes
k '\'='/'
k '/'='\'
k x=x
f x=take(10*x+2)
w#h=map(f w.cycle).f h.drop 9.cycle$(++).reverse=<<map(map k)$["\/\ /"," \ / "," \ / "," \/ "," /\ "]
Try it online!
add a comment |
up vote
1
down vote
up vote
1
down vote
Haskell, 179 bytes
k '\'='/'
k '/'='\'
k x=x
f x=take(10*x+2)
w#h=map(f w.cycle).f h.drop 9.cycle$(++).reverse=<<map(map k)$["\/\ /"," \ / "," \ / "," \/ "," /\ "]
Try it online!
Haskell, 179 bytes
k '\'='/'
k '/'='\'
k x=x
f x=take(10*x+2)
w#h=map(f w.cycle).f h.drop 9.cycle$(++).reverse=<<map(map k)$["\/\ /"," \ / "," \ / "," \/ "," /\ "]
Try it online!
edited 3 hours ago
answered 3 hours ago
ovs
18.1k21058
18.1k21058
add a comment |
add a comment |
up vote
0
down vote
Perl 5 -p
, 148 bytes
$_='3A3'x$_.$/.'3B3
3A3
2/2\2
1/4\1
A6A
B6B
1\4/1
2\2/2
3B3
3A3
'=~s/^.*$/$&x$_/mger x<>.'3B3'x$_;s|A+|/\|g;s|B+|\/|g;s/d/$"x$&/ge;s|^ | |gm
Try it online!
add a comment |
up vote
0
down vote
Perl 5 -p
, 148 bytes
$_='3A3'x$_.$/.'3B3
3A3
2/2\2
1/4\1
A6A
B6B
1\4/1
2\2/2
3B3
3A3
'=~s/^.*$/$&x$_/mger x<>.'3B3'x$_;s|A+|/\|g;s|B+|\/|g;s/d/$"x$&/ge;s|^ | |gm
Try it online!
add a comment |
up vote
0
down vote
up vote
0
down vote
Perl 5 -p
, 148 bytes
$_='3A3'x$_.$/.'3B3
3A3
2/2\2
1/4\1
A6A
B6B
1\4/1
2\2/2
3B3
3A3
'=~s/^.*$/$&x$_/mger x<>.'3B3'x$_;s|A+|/\|g;s|B+|\/|g;s/d/$"x$&/ge;s|^ | |gm
Try it online!
Perl 5 -p
, 148 bytes
$_='3A3'x$_.$/.'3B3
3A3
2/2\2
1/4\1
A6A
B6B
1\4/1
2\2/2
3B3
3A3
'=~s/^.*$/$&x$_/mger x<>.'3B3'x$_;s|A+|/\|g;s|B+|\/|g;s/d/$"x$&/ge;s|^ | |gm
Try it online!
answered 2 hours ago
Xcali
4,870520
4,870520
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f175619%2fdraw-this-diamond-pattern%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Loosely related
– Luis Mendo
2 hours ago