22
4
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.
1Can we use different output characters, or does it need to be consistent? – Emigna – 2018-11-06T18:13:56.833
@Emigna Different characters are fine. – AdmBorkBork – 2018-11-06T18:26:21.383
1Quite related. – Charlie – 2018-11-07T11:06:55.820