### Communities

tag:snake search within a tag
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
created:<1w created < 1 week ago
post_type:xxxx type of post
Challenges

# Circle of text characters

+0
−0

Given a radius R, output a text representation of a circle.

## Input

• A positive integer R (strictly greater than zero)
• You do not need to handle values of R greater than 32

## Output

• A square grid of characters of side length 2R + 1
• You may choose any 2 distinct characters to represent the foreground (depicting the circle) and the background
• The centre of the circle is the centre of the square. That is, the location (R, R) if using zero indexed coordinates
• Each foreground character must have a distance from the centre that has either a floor or a ceiling of R. That is, R-1 < distance < R+1. Within a single output, some foreground characters may have a floor of R and some may have a ceiling of R - you do not need to choose one or other consistently
• The circle must not have gaps. Specifically, there must be no connected path of horizontally or vertically adjacent background characters joining the centre to any edge of the square. Equivalently, a flood fill from the centre will not reach any of the edges

## Examples

Here . represents the background and # represents the foreground.

Using these characters, the rules are equivalent to:

• Every . must be included in the background
• Any # may be included in the foreground, but not all of them need to be - some may be left as background provided there are no gaps between the foreground characters

This is intended to give the flexibility to allow various different circle drawing approaches to compete.

The potential character placements for radius 1 to 10:

R = 1

###
#.#
###

R = 2

#####
##.##
#...#
##.##
#####

R = 3

.#####.
###.###
##...##
#.....#
##...##
###.###
.#####.

R = 4

..#####..
.###.###.
##.....##
##.....##
#.......#
##.....##
##.....##
.###.###.
..#####..

R = 5

..#######..
.####.####.
###.....###
##.......##
##.......##
#.........#
##.......##
##.......##
###.....###
.####.####.
..#######..

R = 6

...#######...
..####.####..
.##.......##.
##.........##
##.........##
##.........##
#...........#
##.........##
##.........##
##.........##
.##.......##.
..####.####..
...#######...

R = 7

....#######....
..#####.#####..
.###.......###.
.##.........##.
##...........##
##...........##
##...........##
#.............#
##...........##
##...........##
##...........##
.##.........##.
.###.......###.
..#####.#####..
....#######....

R = 8

....#########....
...#####.#####...
..###.......###..
.###.........###.
###...........###
##.............##
##.............##
##.............##
#...............#
##.............##
##.............##
##.............##
###...........###
.###.........###.
..###.......###..
...#####.#####...
....#########....

R = 9

.....#########.....
....#####.#####....
..####.......####..
..##...........##..
.##.............##.
###.............###
##...............##
##...............##
##...............##
#.................#
##...............##
##...............##
##...............##
###.............###
.##.............##.
..##...........##..
..####.......####..
....#####.#####....
.....#########.....

R = 10

......#########......
....######.######....
...###.........###...
..###...........###..
.###.............###.
.##...............##.
##.................##
##.................##
##.................##
##.................##
#...................#
##.................##
##.................##
##.................##
##.................##
.##...............##.
.###.............###.
..###...........###..
...###.........###...
....######.######....
......#########......


## Validator

You can validate specific outputs with this text circle validator, which will give a reason for any failed validations.

Explanations are optional, but I'm more likely to upvote answers that have one.

Why does this post require moderator attention?
Why should this post be closed?