ASCII Art Octagons
Clash Royale CLAN TAG#URR8PPP
up vote
5
down vote
favorite
Given an input integer n > 1
, output an ASCII-art octagon with side lengths composed of n
characters. See examples below:
n=2
##
# #
# #
##
n=3
###
# #
# #
# #
# #
# #
###
n=4
####
# #
# #
# #
# #
# #
# #
# #
# #
####
n=5
#####
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
#####
and so on.
You can print it to STDOUT or return it as a function result.
Any amount of extraneous whitespace is acceptable, so long as the characters line up appropriately.
Rules and I/O
- Input and output can be given by any convenient method.
- You can use any printable ASCII character instead of the
#
(except space), but the "background" character must be space (ASCII 32). - Either a full program or a function are acceptable.
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
5
down vote
favorite
Given an input integer n > 1
, output an ASCII-art octagon with side lengths composed of n
characters. See examples below:
n=2
##
# #
# #
##
n=3
###
# #
# #
# #
# #
# #
###
n=4
####
# #
# #
# #
# #
# #
# #
# #
# #
####
n=5
#####
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
#####
and so on.
You can print it to STDOUT or return it as a function result.
Any amount of extraneous whitespace is acceptable, so long as the characters line up appropriately.
Rules and I/O
- Input and output can be given by any convenient method.
- You can use any printable ASCII character instead of the
#
(except space), but the "background" character must be space (ASCII 32). - Either a full program or a function are acceptable.
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
Can we use different output characters, or does it need to be consistent?
â Emigna
22 mins ago
@Emigna Different characters are fine.
â AdmBorkBork
9 mins ago
add a comment |Â
up vote
5
down vote
favorite
up vote
5
down vote
favorite
Given an input integer n > 1
, output an ASCII-art octagon with side lengths composed of n
characters. See examples below:
n=2
##
# #
# #
##
n=3
###
# #
# #
# #
# #
# #
###
n=4
####
# #
# #
# #
# #
# #
# #
# #
# #
####
n=5
#####
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
#####
and so on.
You can print it to STDOUT or return it as a function result.
Any amount of extraneous whitespace is acceptable, so long as the characters line up appropriately.
Rules and I/O
- Input and output can be given by any convenient method.
- You can use any printable ASCII character instead of the
#
(except space), but the "background" character must be space (ASCII 32). - Either a full program or a function are acceptable.
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
Given an input integer n > 1
, output an ASCII-art octagon with side lengths composed of n
characters. See examples below:
n=2
##
# #
# #
##
n=3
###
# #
# #
# #
# #
# #
###
n=4
####
# #
# #
# #
# #
# #
# #
# #
# #
####
n=5
#####
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
# #
#####
and so on.
You can print it to STDOUT or return it as a function result.
Any amount of extraneous whitespace is acceptable, so long as the characters line up appropriately.
Rules and I/O
- Input and output can be given by any convenient method.
- You can use any printable ASCII character instead of the
#
(except space), but the "background" character must be space (ASCII 32). - Either a full program or a function are acceptable.
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
edited 40 mins ago
asked 45 mins ago
AdmBorkBork
25.2k361220
25.2k361220
Can we use different output characters, or does it need to be consistent?
â Emigna
22 mins ago
@Emigna Different characters are fine.
â AdmBorkBork
9 mins ago
add a comment |Â
Can we use different output characters, or does it need to be consistent?
â Emigna
22 mins ago
@Emigna Different characters are fine.
â AdmBorkBork
9 mins ago
Can we use different output characters, or does it need to be consistent?
â Emigna
22 mins ago
Can we use different output characters, or does it need to be consistent?
â Emigna
22 mins ago
@Emigna Different characters are fine.
â AdmBorkBork
9 mins ago
@Emigna Different characters are fine.
â AdmBorkBork
9 mins ago
add a comment |Â
4 Answers
4
active
oldest
votes
up vote
4
down vote
05AB1E, 3 bytes
7ÃÂÃÂ
Try it online!
Explanation
# implicit input as length
# implicit input as string to print
7ÃÂ # range [0...7] as directions
ÃÂ # canvas print
See this answer to understand the 05AB1E canvas.
add a comment |Â
up vote
2
down vote
Canvas, 15 14 12 bytes
ï¼Ââ¸âµâ·+ÃÂï¼Âï¼Â⤢ï½Â≼
Try it here!
Explanation:
/ a diagonal of length n
⸠the input,
âµ ceiling divided by 2, (storing the remainder)
â· minus one
#ÃÂ repeat "#" that many times
+ append that to the diagonal
:⤢n overlap that with its transpose
≼ quad-palindromize with the overlap being the remainder stored earlier
add a comment |Â
up vote
0
down vote
Charcoal, 5 bytes
GH*N#
My first answer with Charcoal!
Explaination:
GH*N# //Full program
GH //Draw a hollow polygon
* //with 8 sides
ï¼® //of side length from input
# //using '#' character
Try it online!
add a comment |Â
up vote
0
down vote
R, 122 bytes
function(n)m=matrix(" ",y<-3*n-2,y)
m[cbind(c(x<-c(rep(1,n-1),1:(2*n-1)),y+1-x),rev(x))]=0
write(pmax(m,rev(m)),1,y,,"")
Try it online!
add a comment |Â
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
05AB1E, 3 bytes
7ÃÂÃÂ
Try it online!
Explanation
# implicit input as length
# implicit input as string to print
7ÃÂ # range [0...7] as directions
ÃÂ # canvas print
See this answer to understand the 05AB1E canvas.
add a comment |Â
up vote
4
down vote
05AB1E, 3 bytes
7ÃÂÃÂ
Try it online!
Explanation
# implicit input as length
# implicit input as string to print
7ÃÂ # range [0...7] as directions
ÃÂ # canvas print
See this answer to understand the 05AB1E canvas.
add a comment |Â
up vote
4
down vote
up vote
4
down vote
05AB1E, 3 bytes
7ÃÂÃÂ
Try it online!
Explanation
# implicit input as length
# implicit input as string to print
7ÃÂ # range [0...7] as directions
ÃÂ # canvas print
See this answer to understand the 05AB1E canvas.
05AB1E, 3 bytes
7ÃÂÃÂ
Try it online!
Explanation
# implicit input as length
# implicit input as string to print
7ÃÂ # range [0...7] as directions
ÃÂ # canvas print
See this answer to understand the 05AB1E canvas.
edited 7 mins ago
answered 23 mins ago
Emigna
44.3k431134
44.3k431134
add a comment |Â
add a comment |Â
up vote
2
down vote
Canvas, 15 14 12 bytes
ï¼Ââ¸âµâ·+ÃÂï¼Âï¼Â⤢ï½Â≼
Try it here!
Explanation:
/ a diagonal of length n
⸠the input,
âµ ceiling divided by 2, (storing the remainder)
â· minus one
#ÃÂ repeat "#" that many times
+ append that to the diagonal
:⤢n overlap that with its transpose
≼ quad-palindromize with the overlap being the remainder stored earlier
add a comment |Â
up vote
2
down vote
Canvas, 15 14 12 bytes
ï¼Ââ¸âµâ·+ÃÂï¼Âï¼Â⤢ï½Â≼
Try it here!
Explanation:
/ a diagonal of length n
⸠the input,
âµ ceiling divided by 2, (storing the remainder)
â· minus one
#ÃÂ repeat "#" that many times
+ append that to the diagonal
:⤢n overlap that with its transpose
≼ quad-palindromize with the overlap being the remainder stored earlier
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Canvas, 15 14 12 bytes
ï¼Ââ¸âµâ·+ÃÂï¼Âï¼Â⤢ï½Â≼
Try it here!
Explanation:
/ a diagonal of length n
⸠the input,
âµ ceiling divided by 2, (storing the remainder)
â· minus one
#ÃÂ repeat "#" that many times
+ append that to the diagonal
:⤢n overlap that with its transpose
≼ quad-palindromize with the overlap being the remainder stored earlier
Canvas, 15 14 12 bytes
ï¼Ââ¸âµâ·+ÃÂï¼Âï¼Â⤢ï½Â≼
Try it here!
Explanation:
/ a diagonal of length n
⸠the input,
âµ ceiling divided by 2, (storing the remainder)
â· minus one
#ÃÂ repeat "#" that many times
+ append that to the diagonal
:⤢n overlap that with its transpose
≼ quad-palindromize with the overlap being the remainder stored earlier
edited 10 mins ago
answered 39 mins ago
dzaima
13.7k21653
13.7k21653
add a comment |Â
add a comment |Â
up vote
0
down vote
Charcoal, 5 bytes
GH*N#
My first answer with Charcoal!
Explaination:
GH*N# //Full program
GH //Draw a hollow polygon
* //with 8 sides
ï¼® //of side length from input
# //using '#' character
Try it online!
add a comment |Â
up vote
0
down vote
Charcoal, 5 bytes
GH*N#
My first answer with Charcoal!
Explaination:
GH*N# //Full program
GH //Draw a hollow polygon
* //with 8 sides
ï¼® //of side length from input
# //using '#' character
Try it online!
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Charcoal, 5 bytes
GH*N#
My first answer with Charcoal!
Explaination:
GH*N# //Full program
GH //Draw a hollow polygon
* //with 8 sides
ï¼® //of side length from input
# //using '#' character
Try it online!
Charcoal, 5 bytes
GH*N#
My first answer with Charcoal!
Explaination:
GH*N# //Full program
GH //Draw a hollow polygon
* //with 8 sides
ï¼® //of side length from input
# //using '#' character
Try it online!
edited 5 mins ago
answered 10 mins ago
Cowabunghole
863418
863418
add a comment |Â
add a comment |Â
up vote
0
down vote
R, 122 bytes
function(n)m=matrix(" ",y<-3*n-2,y)
m[cbind(c(x<-c(rep(1,n-1),1:(2*n-1)),y+1-x),rev(x))]=0
write(pmax(m,rev(m)),1,y,,"")
Try it online!
add a comment |Â
up vote
0
down vote
R, 122 bytes
function(n)m=matrix(" ",y<-3*n-2,y)
m[cbind(c(x<-c(rep(1,n-1),1:(2*n-1)),y+1-x),rev(x))]=0
write(pmax(m,rev(m)),1,y,,"")
Try it online!
add a comment |Â
up vote
0
down vote
up vote
0
down vote
R, 122 bytes
function(n)m=matrix(" ",y<-3*n-2,y)
m[cbind(c(x<-c(rep(1,n-1),1:(2*n-1)),y+1-x),rev(x))]=0
write(pmax(m,rev(m)),1,y,,"")
Try it online!
R, 122 bytes
function(n)m=matrix(" ",y<-3*n-2,y)
m[cbind(c(x<-c(rep(1,n-1),1:(2*n-1)),y+1-x),rev(x))]=0
write(pmax(m,rev(m)),1,y,,"")
Try it online!
answered 2 mins ago
Giuseppe
15.7k31051
15.7k31051
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%2f175408%2fascii-art-octagons%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
Can we use different output characters, or does it need to be consistent?
â Emigna
22 mins ago
@Emigna Different characters are fine.
â AdmBorkBork
9 mins ago