Beta

Build your own dice

Description:

Build your own dice

In this kata we'll practice using multi-dimensional arrays. If we think of a simple array as a one-dimensional object, we can create 2D or 3D objects using arrays of arrays or arrays of arrays of arrays, respectively. Here, we'll create 3D dice, which mimic some properties of real dice.

You'll be given an integer n, and you'll need to make a cubic-shaped die which has sides of length n. In the exact center of each 'side', you'll place an integer, from 1 to 6. The orientation isn't important, as long as the sums of the opposite sides add to 7, as with a normal die. The other spaces should contain zeros.

For example, a 3x3x3 die (n=3) would have one side resembling the following, with a 5 in the middle and zeros in the eight spaces all around it:

    - - -
  | 0 0 0 |
  | 0 5 0 |
  | 0 0 0 |
    - - -  

which would be represented in the code as:

[ [0,0,0], [0,5,0], [0,0,0] ]

In this example, it helps to think of the n=3 die as a cube of 27 smaller blocks, each containing an integer, which should help you identify where the non-zero numbers should go.

If integer n doesn't allow you to create exact centers on the sides, you should return an empty array [].

Arrays
Geometry
Fundamentals

Stats:

CreatedJun 30, 2020
PublishedJun 30, 2020
Warriors Trained66
Total Skips17
Total Code Submissions49
Total Times Completed7
PHP Completions7
Total Stars1
% of votes with a positive feedback rating50% of 4
Total "Very Satisfied" Votes1
Total "Somewhat Satisfied" Votes2
Total "Not Satisfied" Votes1
Total Rank Assessments3
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • heagerty Avatar
Ad