Draw numbers as dice patternsDraw numbers as dice patterns
The way points are assigned on a dice follows a regular pattern, the center dot is present if and only if the number is odd. To represent the even numbers, pairs of dots on opposite sides of the center are added, which will stay present for all successive numbers.
1:
O
2: 3: 4: 5: 6:
O O O O O O O O
O O O O
O O O O O O O O
This "dice pattern" can be extended to numbers greater than 6.
- The dots are arranged in a square of size k with k*k>=n
- the dots are added in layers for the center outwards
- first the corners are added
- then the midpoints of the sides, first on the vertical, then on the horizontal sides.
- for the remaining pairs of dots on each level you can choose any convenient order
// one possible way to add the remaining dots
7: 8:
O O OOO
OOO O O
O O OOO
10: 12: 14: 16: 18: 20: 22: 24:
O O O O O O O O O O O O O O OOO O OOOOO
OOO OOO OOO OOO OOOO OOOOO OOOOO OOOOO
O O O O OO OO OO OO OO OO OO OO OO OO OO OO
OOO OOO OOO OOO OOOO OOOOO OOOOO OOOOO
O O O O O O O O O O O O O O O OOO OOOOO
26: 30: 32: 36: 40: 44:
O O O O O O O O O OO O OO OO O OO
OOOOO OOOOO OOOOO OOOOOOO OOOOOOO OOOOOOO
OOOOO OOOOO OOOOO OOOOO OOOOO OOOOOOO
OO OO OOO OOO OOO OOO OOO OOO OOO OOO OOO OOO
OOOOO OOOOO OOOOO OOOOO OOOOO OOOOOOO
OOOOO OOOOO OOOOO OOOOOOO OOOOOOO OOOOOOO
O O O O O O O O O OO O OO OO O OO
46: 48:
OOOO OO OOOOOOO
OOOOOOO OOOOOOO
OOOOOOO OOOOOOO
OOO OOO OOO OOO
OOOOOOO OOOOOOO
OOOOOOO OOOOOOO
OO OOOO OOOOOOO
Your task is to write a program of function, that given a positive integer as input prints the dice pattern for that number.
Rules:
- Trailing white-spaces are allowed
- Additional white-spaces at the start of each line are allowed, as long as all lines are indented by the same amount
- You can replace
O
by any non-whitespace character - You may return a matrix of Truthy/Falsey values instead of printing the outputs
- Your program has to work for inputs at least up to 2601=51*51, but your algorithm should work for arbitrarily large numbers
- This is code-golf the shortest solution in bytes wins
code-golf ascii-art open-ended-function
related
Meta:
- Is this a duplicate?
- Is my explanation clear?