-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVisible_Dots_On_a_Die.php
More file actions
25 lines (21 loc) · 926 Bytes
/
Visible_Dots_On_a_Die.php
File metadata and controls
25 lines (21 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
/**
* Your task is to return the number of visible dots on a die after it has been rolled(that means the total count of dots that would not be touching the table when rolled)
*
* 6, 8, 10, 12, 20 sided dice are the possible inputs for "numOfSides"
*
* topNum is equal to the number that is on top, or the number that was rolled.
*
* for this exercise, all opposite faces add up to be 1 more than the total amount of sides
* Example: 6 sided die would have 6 opposite 1, 4 opposite 3, and so on. for this exercise, the 10 sided die starts at 1 and ends on 10.
*
* Note: topNum will never be greater than numOfSides
*
* */
function totalAmountVisible(int $topNum, int $numOfSides): int {
//Calcular la suma de todas las caras del dado.
$suma = ($numOfSides * ($numOfSides + 1)) / 2;
//Calcular el numero oculto
$downNum = $numOfSides + 1 - $topNum;
return $suma - $downNum;
}