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 [].
Similar Kata:
Stats:
Created | Jun 30, 2020 |
Published | Jun 30, 2020 |
Warriors Trained | 66 |
Total Skips | 17 |
Total Code Submissions | 49 |
Total Times Completed | 7 |
PHP Completions | 7 |
Total Stars | 1 |
% of votes with a positive feedback rating | 50% of 4 |
Total "Very Satisfied" Votes | 1 |
Total "Somewhat Satisfied" Votes | 2 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 3 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |