Skip to main content
posted challange
Source Link
bsoelch
  • 6k
  • 4
  • 5

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 the shortest solution in bytes wins

related

Meta:

  • Is this a duplicate?
  • Is my explanation clear?

Draw 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 the shortest solution in bytes wins

related

Meta:

  • Is this a duplicate?
  • Is my explanation clear?
clarify limit
Source Link
bsoelch
  • 6k
  • 4
  • 5
  • 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.
  • then the midpoints offor the remaining segments (if the length is not a powerpairs of two, take the point closer to the corner), again first on the vertical, thendots on the horizontal sides, starting that the top-left corner
  • ...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
  • 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. (Meta: should I remove this rule?) 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 492601=51*51, but your algorithm should work for arbitrarily large numbers
  • This is the shortest solution in bytes wins

optional additional requirement

Support arbitrarily large (up to you languages integer limit) input numbers.

Solutions with this requirement do not compete with the more restricted solutions.

  • first the corners are added
  • then the midpoints of the sides, first on the vertical, then on the horizontal sides.
  • then the midpoints of the remaining segments (if the length is not a power of two, take the point closer to the corner), again first on the vertical, then on the horizontal sides, starting that the top-left corner
  • ...
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
  • 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. (Meta: should I remove this rule?)
  • Your program has to work for inputs at least up to 49
  • This is the shortest solution in bytes wins

optional additional requirement

Support arbitrarily large (up to you languages integer limit) input numbers.

Solutions with this requirement do not compete with the more restricted solutions.

  • 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
  • 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 the shortest solution in bytes wins

added 13 characters in body
Source Link
bsoelch
  • 6k
  • 4
  • 5
  • 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. (metaMeta: should I remove this rule?)
  • Your program has to work for inputs at least up to 49
  • This is the shortest solution in bytes wins
  • 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. (meta: remove this rule?)
  • Your program has to work for inputs at least up to 49
  • This is the shortest solution in bytes wins
  • 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. (Meta: should I remove this rule?)
  • Your program has to work for inputs at least up to 49
  • This is the shortest solution in bytes wins
Source Link
bsoelch
  • 6k
  • 4
  • 5
Loading